text 转换成datetime

来源:百度知道 编辑:UC知道 时间:2024/06/14 07:17:32
string sq= "Select LessonName,StudyTime from Assistant where LessonName='" + textBox1.Text + "'and StudyTime='"+(DateTime)dateTimePicker1.Text+"''"+(DateTime)comboBox2.Items+"''"+comboBox3.Items+"'";
想问下,这样写为什么提示说,无法将错误 1 无法将类型“string”转换为“System.DateTime”

错误 2 无法将类型“System.Windows.Forms.ComboBox.ObjectCollection”转换为“System.DateTime”

那个Studytiem 是 datetime 类型的。

第一个错误应该是字符串的格式问题,看看你那个text的格式。

第二个错误类型转换失败,你不能将comboBox2.items转换为datetime型的,检查下你这的代码。 应该是comboBox2.items(2).text..之类的