The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value. The statement has been terminated

14 Haziran 2010 – 09:58

sql sorgulamada datetime türünde yaptığınız sorgularda “The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value. The statement has been terminated” problemi ile karşılaşıyorsanız sorgunuza değeri gönderirken .ToString(“MM.dd.yyyy hh:mm:ss”) şeklinde düzenleyip göndrirseniz probleminiz çözülür.

?View Code CSHARP
SqlConnection con = new SqlConnection(/* kendi sql baglanma cümleniz */);
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = con;
            DateTime dt = new DateTime(2010,6,10,0,0,0); // 10 haziran
            DateTime dt1 = new DateTime(2010, 6, 11, 0, 0, 0); // 11 haziran
 
            cmd.CommandText = "select * from tblDeneme where time>'" + dt.ToString("MM.dd.yyyy hh:mm:ss") + "' and time<'" + dt1.ToString("MM.dd.yyyy hh:mm:ss") + "'";
' kendi sql baglanma cümleniz 
2	Dim con As New SqlConnection()
3	Dim cmd As New SqlCommand()
4	cmd.Connection = con
5	Dim dt As New DateTime(2010, 6, 10, 0, 0, 0)
6	' 10 haziran
7	Dim dt1 As New DateTime(2010, 6, 11, 0, 0, 0)
8	' 11 haziran
9	cmd.CommandText = ("select * from tblDeneme where time>'" + dt.ToString("MM.dd.yyyy hh:mm:ss") & "' and time<'") + dt1.ToString("MM.dd.yyyy hh:mm:ss") & "'"
Bookmark and Share

Post a Comment

Subscribe without commenting