新手求大神解决c# 从字符串转换日期和/或时间时,转换失败。 10
想要利用dateTimePicker来选出两个时间段之间的数据。SqlConnectionconnection1=newSqlConnection(connString)...
想要利用dateTimePicker来选出两个时间段之间的数据。
SqlConnection connection1 = new SqlConnection(connString);
DateTime dts = Convert.ToDateTime(dateTimePicker1.Text);
DateTime dte = Convert.ToDateTime(dateTimePicker2.Text);
string sql1 = String.Format("select time,ID,X,Y,Z from dbo.test002 where datediff(day,@dts,time) >=0 and datediff(day,time,@dte) >=0");
//string sql1 = String.Format("select time,ID,X,Y,Z from dbo.test002 where datediff(day,@dts,time) >=0 and datediff(day,time,@dte) >=0");
SqlParameter parameter1 = new SqlParameter("@row", SqlDbType.Int);
SqlParameter parameter2 = new SqlParameter("@dts", dts);
SqlParameter parameter3 = new SqlParameter("@dte", dte);
parameter1.Value = j;
SqlCommand command1 = new SqlCommand(sql1, connection1);
command1.Parameters.Add(parameter1);
command1.Parameters.Add(parameter3);
command1.Parameters.Add(parameter2);
connection1.Open();
SqlDataReader dataReader1 = command1.ExecuteReader();在这个地方报错从字符串转换日期和/或时间时,转换失败。
求大神帮忙啊。如果代码错了的话小弟求一下正确的啊 展开
SqlConnection connection1 = new SqlConnection(connString);
DateTime dts = Convert.ToDateTime(dateTimePicker1.Text);
DateTime dte = Convert.ToDateTime(dateTimePicker2.Text);
string sql1 = String.Format("select time,ID,X,Y,Z from dbo.test002 where datediff(day,@dts,time) >=0 and datediff(day,time,@dte) >=0");
//string sql1 = String.Format("select time,ID,X,Y,Z from dbo.test002 where datediff(day,@dts,time) >=0 and datediff(day,time,@dte) >=0");
SqlParameter parameter1 = new SqlParameter("@row", SqlDbType.Int);
SqlParameter parameter2 = new SqlParameter("@dts", dts);
SqlParameter parameter3 = new SqlParameter("@dte", dte);
parameter1.Value = j;
SqlCommand command1 = new SqlCommand(sql1, connection1);
command1.Parameters.Add(parameter1);
command1.Parameters.Add(parameter3);
command1.Parameters.Add(parameter2);
connection1.Open();
SqlDataReader dataReader1 = command1.ExecuteReader();在这个地方报错从字符串转换日期和/或时间时,转换失败。
求大神帮忙啊。如果代码错了的话小弟求一下正确的啊 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询