from_date to to_date using datetimepicker

dualshock03

Well-known member
Joined
Jan 28, 2007
Messages
105
Programming Experience
1-3
Hi people, how will i code to create a search filter by start and end date in searching records from Database, then show it on the system controls.

for example i have 2 date controlers(e.g. using DatetimePicker control), the other is for the start date, and another for the end date.. then i have a search button that would generate the result on my textboxes depending on the given start date (from_date) and the end date(to_date)..

thats all thankzz.. :D
 
See Data Walkthroughs, especially "Creating a Form to Search Data". In your case you will create a query with two date parameters and name a for example "FillByDates" method that you use in button click. The query could look like this:
VB.NET:
SELECT * FROM Table1 WHERE birth >= @fromdate AND birth <=@todate
The wizard here creates a toolstrip with two textboxes and the search button, which is not optimal for date input. It is possible to put DTP controls in toolstrip too with code (see thread http://www.vbdotnetforums.com/menus-toolbars/8096-how-add-datetimepicker-toolstrip.html), but for now get started with the tutorial to see how it works. You can use your form DTP values as second and third parameters for the FillByDates call, similar to this:
VB.NET:
Me.Table1TableAdapter.FillByDates(Me.TestExDataSet.Table1, Me.DateTimePicker1.Value.Date, Me.DateTimePicker2.Value.Date)
 
"Object reference not set to an instance of an object."

Hi i tried creating this code, but an error ocurred telling that "Object reference not set to an instance of an object."
VB.NET:
Private Sub btn_VCR_generate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_VCR_generate.Click
    Try
        con1.Open()
        comDateSearch.CommandText = ((" SELECT tblpersonaldata.accussed_No,tblpersonaldata.accusedname, date_format(tblpersonaldata.dateofbirth, '%b, % d, % Y') FROM tblpersonaldata WHERE tblpersonaldata.dateofbirth Between '") + dfromvalue.Value.ToString("MM-dd-yyyy") & "'AND '") + dtovalue.Value.ToString("MM-dd-yyyy") & "'"
        DateSearchAdap.SelectCommand = comDateSearch

        readate = comDateSearch.ExecuteReader

        While readate.Read
            txtsusId.Text = (readate.GetValue(readate.GetOrdinal("accussed_No")))
            txtfulname.Text = (readate.GetValue(readate.GetOrdinal("accusedname")))
        End While
    Catch SQL_err As MySql.Data.MySqlClient.MySqlException
        MsgBox("ERROR" & SQL_err.Message)
    End Try
    con1.Close()
End Sub
 
I strongly recommend you have a look at using the designers for data access. You have those walk-throughs i linked to, there are many more tutorials on the web, and there are many videos available that can also show you how to do this, for example these: Visual Basic How Do I Video Series
If you're going to write data access code yourself you need to learn about parameterized queries.
 

Latest posts

Back
Top