调试c#程序,跳出 标准表达式中数据类型不匹配。部分代码如下:
stringstrConnection2="Provider=Microsoft.Jet.OLEDB.4.0;DataSource=db_wygl.mdb";OleDbC...
string strConnection2 = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=db_wygl.mdb";
OleDbConnection objConnection2 = new OleDbConnection(strConnection2); //建立连接
objConnection2.Open();
string sql2 = "select * from tab_smoney where 计费起始日期='#" + dateTimePicker1.Value.ToString("yyyy-MM-dd") + "#'and 计费终止日期='#" + dateTimePicker2.Value.ToString("yyyy-MM-dd") + "#'";
OleDbDataAdapter myda2 = new OleDbDataAdapter(sql2, objConnection2);
DataSet myds2 = new DataSet();
myda2.Fill(myds2,"计费起始日期");
dataGridView1.DataSource = myds2.Tables["计费起始日期"];
objConnection2.Close(); 展开
OleDbConnection objConnection2 = new OleDbConnection(strConnection2); //建立连接
objConnection2.Open();
string sql2 = "select * from tab_smoney where 计费起始日期='#" + dateTimePicker1.Value.ToString("yyyy-MM-dd") + "#'and 计费终止日期='#" + dateTimePicker2.Value.ToString("yyyy-MM-dd") + "#'";
OleDbDataAdapter myda2 = new OleDbDataAdapter(sql2, objConnection2);
DataSet myds2 = new DataSet();
myda2.Fill(myds2,"计费起始日期");
dataGridView1.DataSource = myds2.Tables["计费起始日期"];
objConnection2.Close(); 展开
1个回答
展开全部
string sql2 = "select * from tab_smoney where 计费起始日期='#" + dateTimePicker1.Value.ToString("yyyy-MM-dd") + "#'and 计费终止日期='#" + dateTimePicker2.Value.ToString("yyyy-MM-dd") + "#'";
计费起始日期这个字段是不是日期类型的,如果是的话,你后面的应该再转成DateTime类型
计费起始日期这个字段是不是日期类型的,如果是的话,你后面的应该再转成DateTime类型
追问
计费起始日期 是短日期型的,你说的后面的应该再转成DateTime类型,我刚接触不太明白,能说仔细些吗?谢谢
追答
dateTimePicker1.Value.ToString("yyyy-MM-dd")改成:
DateTime.Parse(dateTimePicker1.Value.ToString("yyyy-MM-dd"))
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询