Click here to Skip to main content
15,886,075 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am using vb.net and sql server. this is my code to search for rows using date value from a datetimepicker control. the problem is even though i enter a date value which is already there in the database i still don't get any rows. what is the problem? is it something to do with the formatting of the date values or?

VB
sqlsearch = "Select * from Students where  student_dob =@dob"
Dim da As New SqlDataAdapter(sqlsearch, con)
da.SelectCommand.Parameters.AddWithValue("@dob", DateTimePicker1.Value)
da.Fill(ds)
con.Close()
If ds.Tables(0).Rows.Count = 0 Then
MessageBox.Show("No record exists, try again", "SORRY!", MessageBoxButtons.OK)
Else
populate_lvw1()
End If
Posted
Comments
DamithSL 22-Dec-14 3:16am    
what is the column data type of student_dob?
hlsc1983 22-Dec-14 3:23am    
its date type.... of course when I view the columns in sqlserver , it shows date in ' yyyy/mm/ dr format.
DamithSL 22-Dec-14 3:28am    
are you get the message with "no record exist"?
have you debug and check the value of DateTimePicker1.Value and dataset object at runtime?
hlsc1983 22-Dec-14 4:23am    
I checked the value . its something like 13-09-2005 14:52:00
DamithSL 22-Dec-14 5:08am    
try with below
da.SelectCommand.Parameters.AddWithValue("@dob", DateTimePicker1.Value.Date)

1 solution

set the Date of DateTimePicker value as below
VB
da.SelectCommand.Parameters.AddWithValue("@dob", DateTimePicker1.Value.Date)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900