C#+ACCESS 查询"日期"字段值大于指定日期的记录方法

lzpuxx 2009-01-15 09:37:20
我想在C#+ACCESS中查询出记录的日期字段(enter_dat1)大于指定“日期”(TextBox3.Text的值,如:2008-10-09)中的记录,用以下的代码出现 OleDbDataReader reader = cmd.ExecuteReader()处出现“至少有一个参数未指定”的错误,请大家指教,或赐与更简单的方法,谢谢!


string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("~/data/xsgl.mdb");
OleDbConnection conn = new OleDbConnection(strConn);
conn.Open();
DateTime datt = Convert.ToDateTime(TextBox3.Text);
String sql = "select numbe1,nam1,se1,enter_dat1,fiel1 from xsjf where fiel1='" + DropDownList2.SelectedValue.Trim() + "' and enter_dat1 > datt";
OleDbCommand cmd = new OleDbCommand(sql, conn);
OleDbDataReader reader = cmd.ExecuteReader();
GridView2.DataSource = reader;
GridView2.DataBind();
...全文
1065 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
lzpuxx 2009-01-16
  • 打赏
  • 举报
回复
谢谢指教,问题解决!
xuqunying0545 2009-01-15
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 sdfkfkd 的回复:]
String sql = "select numbe1,nam1,se1,enter_dat1,fiel1 from xsjf where fiel1='" + DropDownList2.SelectedValue.Trim() + "' and enter_dat1 > datt";
改成
String sql = "select numbe1,nam1,se1,enter_dat1,fiel1 from xsjf where fiel1='" + DropDownList2.SelectedValue.Trim() + "' and enter_dat1 > #"+datt+"#";
你这个datt应该是变量吧
在ACCESS中,表示日期要用#界定起来,如
select * from table where f…
[/Quote]
up
特别 2009-01-15
  • 打赏
  • 举报
回复
String sql = "select numbe1,nam1,se1,enter_dat1,fiel1 from xsjf where fiel1='" + DropDownList2.SelectedValue.Trim() + "' and enter_dat1 > datt";
改成
String sql = "select numbe1,nam1,se1,enter_dat1,fiel1 from xsjf where fiel1='" + DropDownList2.SelectedValue.Trim() + "' and enter_dat1 > #"+datt+"#";
你这个datt应该是变量吧
在ACCESS中,表示日期要用#界定起来,如
select * from table where field=#2009-01-15#

111,131

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧