数据类型转换
我在数据库中,TIME 定义的是string类型。
private void Search(string comboBox1,string dateTimePicker1,string dateTimePicker2,string comboBox22,string comboBox33,string comboBox44)
{
string SQL="Select *from people where TIME between'" + dateTimePicker1 + "'and'" + dateTimePicker2 + "'";
case "查询":
this.Search(this.comboBox1.SelectedText, this.dateTimePicker1.Value.ToShortDateString(),
this.dateTimePicker2.Value.AddDays(1).ToShortDateString, this.comboBox22.SelectedText,
this.comboBox33.SelectedText, this.comboBox44.SelectedText);
break;
报错了,好像是数据类型转换不过来,SQL语言怎么该?
------解决方案-------------------- ToShortDateString()
------解决方案--------------------
探讨 麻烦楼上不要写的这么简洁。。。我还没懂。。。
------解决方案-------------------- string SQL="Select * from people where TIME between'" + dateTimePicker1 + "'and'" + dateTimePicker2 + "'";//dateTimePicker1 dateTimePicker2 是两个控件的名字
你干脆把dateTimePicker1 dateTimePicker2的值取出来赋给两个字符串,
------解决方案-------------------- .ToShortDateString() 跟机器的时间格式有关
格式化一下.ToString("yyyy-MM-dd")
如果你用SqlCommand传参,用强类型的就没这问题了