我今天要尝试排序。我在比较时给出了匹配错误。
OleDbConnection baglanti = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\Users\\Dragonfly\\Documents\\Visual Studio 2013\\WebSites\\WebSite2\\App_Data\\calismagunluk.mdb");
OleDbDataReader oku;
OleDbCommand sorgu =new OleDbCommand();
DateTime bugun = DateTime.Now.Date;
sorgu.CommandText = "select * from calisan where kulID=" + sesionKulId +
" AND gun='" + bugun + "' ";
oku = sorgu.ExecuteReader();//I give error in here
if (oku.HasRows) {
Repeater1.DataSource = oku;
Repeater1.DataBind();
oku.Dispose();}
else{
Repeater1.Visible = false;
repeaterBos.Text = "Bugün Hiç Çalışma Yapmamışsınız...";
oku.Dispose();
}
我收到此错误:"标准表达式中的数据类型不匹配"。
如果我将db列更改为Text,则它正在运行。但我不是这样想的。我该怎么做?
答案 0 :(得分:2)
您可以绕过格式问题,并通过使用参数让命令自行处理格式:
OleDbConnection baglanti = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\Users\\Dragonfly\\Documents\\Visual Studio 2013\\WebSites\\WebSite2\\App_Data\\calismagunluk.mdb");
OleDbDataReader oku;
OleDbCommand sorgu =new OleDbCommand();
DateTime bugun = DateTime.Now.Date;
sorgu.CommandText = "select * from calisan where kulID=@ID AND gun=@date";
sorgu.Parameters.Add("@ID", OleDbType.Integer).Value = susionKulId;
sorgu.Parameters.Add("@date", OleDbType.DBTimeStamp).Value = bugun;