C#查询sql中数据,查询时间由datetimepicker给出
C#查询sql中数据,时间由datetimepicker给出,提示错误从 char 数据类型到 datetime 数据类型的转换导致 datetime 值越界。
代码: string datetime1 = dateTimePicker1.Value.ToString("yyyy/MM/dd/ HH:mm:ss");
string datetime2 = dateTimePicker2.Value.ToString("yyyy/MM/dd/ HH:mm:ss");
string strcom = "SELECT * FROM biao WHERE datetime BETWEEN '"+datetime1+"' AND '"+datetime2+"'";
SqlCommand command = new SqlCommand(strcom);
SqlDataAdapter sda = new SqlDataAdapter(strcom, sqlcon);
DataSet ds1 = new DataSet();
sda.Fill(ds1, "table1"); /*错误处在这里*/
DataTable dt = new DataTable();
dt = ds1.Tables["table1"];
dataGridView4.DataSource = dt.DefaultView;
另外,查询的时间如果从testbox给出
string datetime1=testbox1.text;
这样查询就没有问题,求高手解答??
c#
sql
------解决方案--------------------dd后面多了/
------解决方案-------------------- string datetime1 = dateTimePicker1.Value.ToString("
yyyy/MM/dd HH:mm:ss");