ASP.Net不匹配访问日期/时间列
本文关键字:时间 日期 访问 Net 不匹配 ASP | 更新日期: 2023-09-27 18:11:23
我在试着为今天排序。当我比较时,我给出匹配错误。
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,它正在工作。但我不想这样。我该怎么走?
您可以通过使用参数绕过格式问题,让命令自行处理格式:
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;