Add numbers which are present in db

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rekhasc
    New Member
    • Oct 2007
    • 66

    Add numbers which are present in db

    how to add numbers which is present in database on date basis in vb6.0 using adodc
  • QVeen72
    Recognized Expert Top Contributor
    • Oct 2006
    • 1445

    #2
    Hi,

    use SQL Query:

    Select Sum(Qty) From MyTable

    Regards
    Veena

    Comment

    • jrtox
      New Member
      • Sep 2007
      • 89

      #3
      Originally posted by rekhasc
      how to add numbers which is present in database on date basis in vb6.0 using adodc
      Did you mean Sum of Numbers, which Belong to that particular date.
      eg, Sum of numbers for the date of July 05, 2007
      and another sum for the date july 06, 2007 so on and so fort?

      Comment

      • rekhasc
        New Member
        • Oct 2007
        • 66

        #4
        Originally posted by jrtox
        Did you mean Sum of Numbers, which Belong to that particular date.
        eg, Sum of numbers for the date of July 05, 2007
        and another sum for the date july 06, 2007 so on and so fort?
        i want to add numbers(amounts ) of seven days,month and so on.......date should automatically updated....... i want code for both..........

        Comment

        • QVeen72
          Recognized Expert Top Contributor
          • Oct 2006
          • 1445

          #5
          Hi,

          Use this Query :

          [code=vb]
          sSQL = "Select Sum(Amt) From MyTable Where MyDate Is Between #" & txtFromDate.Tex t & "# And #" & txtToDate.Text & "# "
          [/code]

          REgards
          Veena

          Comment

          • rekhasc
            New Member
            • Oct 2007
            • 66

            #6
            Originally posted by QVeen72
            Hi,

            Use this Query :

            [code=vb]
            sSQL = "Select Sum(Amt) From MyTable Where MyDate Is Between #" & txtFromDate.Tex t & "# And #" & txtToDate.Text & "# "
            [/code]

            REgards
            Veena


            Private Sub cmdshow_Click()
            sSQL = "Select Sum(Amount) From xdetails Where MyDate Is Between #" & txtFromDate.Tex t & "# And #" & txtToDate.Text & "# "
            txtTotal.Text = Val(sSQL)
            End Sub

            but its not adding the amount,........
            mydatabase contains two fields, one is date and another one is amount, when i enter 2 dates it should show the sum of amounts which is in database b/w these dates. ( in database i have given the date format as medium date)

            Comment

            • QVeen72
              Recognized Expert Top Contributor
              • Oct 2006
              • 1445

              #7
              hI,

              What is backend db ..?

              REgards
              Veena

              Comment

              • rekhasc
                New Member
                • Oct 2007
                • 66

                #8
                Originally posted by QVeen72
                hI,

                What is backend db ..?

                REgards
                Veena

                i am using ms access 2000
                instead of entering date in text box can i use combobox

                Comment

                • QVeen72
                  Recognized Expert Top Contributor
                  • Oct 2006
                  • 1445

                  #9
                  Hi,

                  thers is no IS in the query :

                  sSQL = "Select Sum(Amt) From MyTable Where MyDate Between #" & txtFromDate.Tex t & "# And #" & txtToDate.Text & "#


                  Yes, u can use ComboBox :
                  CDate(Combo1.Te xt)

                  Regards
                  Veena

                  Comment

                  • rekhasc
                    New Member
                    • Oct 2007
                    • 66

                    #10
                    Originally posted by QVeen72
                    Hi,

                    thers is no IS in the query :

                    sSQL = "Select Sum(Amt) From MyTable Where MyDate Between #" & txtFromDate.Tex t & "# And #" & txtToDate.Text & "#


                    Yes, u can use ComboBox :
                    CDate(Combo1.Te xt)

                    Regards
                    Veena




                    Dim sSQL As String


                    Private Sub cmdTotal_Click( )
                    sSQL = "Select Sum(Amount) From Table1 Where date Between #" & txtFromDate.Tex t & "# And #" & txtToDate.Text & "# "
                    txtTotal.Text = Val(sSQL)
                    End Sub


                    its not adding the amount......... .
                    when i click the total cmd its coming 0

                    Comment

                    • QVeen72
                      Recognized Expert Top Contributor
                      • Oct 2006
                      • 1445

                      #11
                      Hi,

                      you have to open a recordset, just by giving Val() will not work..
                      what i have given is just a Query.
                      To open a record set, just go through this thread

                      Regards
                      Veena

                      Comment

                      • rekhasc
                        New Member
                        • Oct 2007
                        • 66

                        #12
                        Originally posted by QVeen72
                        Hi,

                        you have to open a recordset, just by giving Val() will not work..
                        what i have given is just a Query.
                        To open a record set, just go through this thread

                        Regards
                        Veena


                        Dim sSQL As String

                        Private Sub cmdAdd_Click()
                        Adodc1.Recordse t.AddNew
                        Text1.SetFocus
                        End Sub

                        Private Sub cmdExit_Click()
                        Unload Me
                        End Sub

                        Private Sub cmdTotal_Click( )
                        sSQL = "Select Sum(Amount) From Table1 Where date Between #" & txtFromDate.Tex t & "# And #" & txtToDate.Text & "# "
                        txtTotal.Text = Val(sSQL)
                        End Sub

                        Comment

                        • QVeen72
                          Recognized Expert Top Contributor
                          • Oct 2006
                          • 1445

                          #13
                          Hi,

                          Declare a Connection object, Recordset Object :

                          [code=vb]
                          Dim sSQL As String
                          Dim AConn As New ADODB.Connectio n
                          Dim RST As New ADODB.Recordset
                          With AConn
                          .ConnectionStri ng = "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source=C:\MyDb. mdb"
                          .Open
                          End With
                          sSQL = "Select Sum(Amount) From Table1 Where date Between #" & txtFromDate.Tex t & "# And #" & txtToDate.Text & "# "
                          RST.Open sSQL, AConn
                          If Not RST.EOF Then
                          txtTotal.Text = RST(0) & ""
                          End If
                          RST.Close
                          [/code]

                          Replace C:\MyDb.mdb, to ur actual database path

                          REgards
                          Veena
                          Last edited by Killer42; Oct 8 '07, 03:29 AM. Reason: Insert a closing quote.

                          Comment

                          • rekhasc
                            New Member
                            • Oct 2007
                            • 66

                            #14
                            Originally posted by QVeen72
                            Hi,

                            Declare a Connection object, Recordset Object :

                            [code=vb]
                            Dim sSQL As String
                            Dim AConn As New ADODB.Connectio n
                            Dim RST As New ADODB.Recordset
                            With AConn
                            .ConnectionStri ng = "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source=C:\MyDb. mdb"
                            .Open
                            End With
                            sSQL = "Select Sum(Amount) From Table1 Where date Between #" & txtFromDate.Tex t & "# And #" & txtToDate.Text & "# "
                            RST.Open sSQL, AConn
                            If Not RST.EOF Then
                            txtTotal.Text = RST(0) & ""
                            End If
                            RST.Close
                            [/code]

                            Replace C:\MyDb.mdb, to ur actual database path

                            REgards
                            Veena


                            thank you.....
                            thanks a lot..........
                            it helps me a lot........ i am d beginner of vb...... i want to learn more about vb..... thats y i m doing small pgms......... thank u for your cooperation
                            Last edited by Killer42; Oct 8 '07, 03:29 AM. Reason: Insert a closing quote on code line 5

                            Comment

                            • rekhasc
                              New Member
                              • Oct 2007
                              • 66

                              #15
                              hi.........

                              i want to know about how to generate a graphs on this query basis.....(dail y,weekly,monthl y,yearly,totall y)........... and also how to print these result plz help me............. ....

                              Comment

                              Working...