how can i get the value accumulated from the date i select from datetimepicker1 to datetimepicker2 in vb.net and mysql? the value here refers to the daily sales and i need to find the total sales between the range dates that i choose..
please help me..as im beginner and my knowledge is limited..
thanks in advance..

Recommended Answers

All 4 Replies

You didnt say exactly where from, so I will assume from database.
You can write an sql query that will look like:

Dim sqlQuery As String = "SELECT * FROM MyTable WHERE DateColumn >= @param1 AND DateColumn <= @param2"
'by using sqlcommand you then define parameters:
cmd.Parameters.Add("@param1", SqlDbType.DateTime).Value = datetimepicker1.Value
cmd.Parameters.Add("@param2", SqlDbType.DateTime).Value = datetimepicker2.Value

You can also use the syntax

Dim sqlQuery As String = "SELECT * FROM MyTable WHERE DateColumn BETWEEN @param1 AND  @param2"

thank you very much to both mitja and jim!!
but there's a problem here , when i select the date retrieving from database from start date to end date, there's an error displaying the result to my listview, where for eg, when i choose dates from 01/10/2011 to 31/10/2011, the result display 3 rows result where i only have 2 results in my database.. is there any problem with my code??

Dim result As MySqlDataReader
        result = Nothing

        Dim cmd2 As New MySqlCommand
        conn = New MySqlConnection("Server = " + _host + ";User ID = " + _user + ";Password = " + _pass + ";database = transportation")

            With cmd2
                .CommandText = "SELECT * FROM driversearned WHERE DateTP >= @dt1 AND DateTP <= @dt2"
                .Connection = conn
                .Parameters.AddWithValue("@dt1", DateTimePicker1.Text.Trim)
                .Parameters.AddWithValue("@dt2", DateTimePicker2.Text.Trim)
            End With
            result = cmd2.ExecuteReader
            With DriversEarnedListView
                .FullRowSelect = True
                .View = View.Details
                .GridLines = True
                .Sorting = Windows.Forms.SortOrder.Ascending
                .Columns.Add("DriversName", 140, HorizontalAlignment.Left)
                .Columns.Add("Charges", 140, HorizontalAlignment.Left)

                Do While result.Read

                    drvname = result.GetString(result.GetOrdinal("DriversName"))
                    comm = result.GetString(result.GetOrdinal("Charges"))

                    NewItem = New ListViewItem(drvname)


                    count = count + 1

            End With

it's ok now..i think i was refering to wrong table...thanks for the help ya!!! ^^

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.