Click here to Skip to main content
15,897,891 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Dear sir/ma'am


i am using visual studio 2005 and sqlserver 2000

sir when i run my webpage then problem occur in the line as
String not recognized as valid date time
VB
cm = New SqlCommand("select * from h_leave where holi_date1='" & Convert.ToDateTime(Me.txt_frmdate.Text).ToString("MM/dd/yyyy") & "' or holi_date2='" & Convert.ToDateTime(Me.txt_todate.Text).ToString("MM/dd/yyyy") & "' or (holi_date1 between '" & Convert.ToDateTime(Me.txt_frmdate.Text).ToString("MM/dd/yyyy") & "' and '" & Convert.ToDateTime(Me.txt_todate.Text).ToString("MM/dd/yyyy") & "')or(holi_date2 between '" & Convert.ToDateTime(Me.txt_frmdate.Text).ToString("MM/dd/yyyy") & "' and '" & Convert.ToDateTime(Me.txt_todate.Text).ToString("MM/dd/yyyy") & "')", con)


help me to check the date value
Posted
v2

Instead of doing this string concatenation garbage, use a parameterized query. Google for "vb.net parameterized query" for what you should be doing and why. Your code introduced security risks that can wipe out your database.
 
Share this answer
 
Instead of Convert.ToDateTime() try
VB
DateTime dt = DateTime.ParseExact(value, format, CultureInfo.InvariantCulture);
 
Share this answer
 
v2

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