查询的时候数据类型不匹配狂郁闷啊~救命啊
蜗牛水里爬 2007-09-06 10:42:44 ACCESS数据中用的是短日期格式
OleDbConnection OleDbcon = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data source=" + Server.MapPath(@"~\QiXin.mdb"));
try
{
DateTime MyDate1 = Convert.ToDateTime(this.TextBoxStartDate.Text.ToString());
DateTime MyDate2 = Convert.ToDateTime(this.TextBoxEndDate.Text.ToString());
string OleDbstr = "select * from DaoDaXieChe where RiQi between'" + MyDate1.ToString("yyyy-mm-dd") + "'and '" + MyDate2.ToString ("yyyy-mm-dd") + "' order by RiQi";
//string OleDbstr = "select * from DaoDaXieChe where RiQi between '2007-7-6' and '2007-8-5' order by RiQi";
//OleDbcon = new OleDbConnection(strCon);
OleDbDataAdapter myda = new OleDbDataAdapter(OleDbstr, OleDbcon);
DataSet myds = new DataSet();
OleDbcon.Open();
myda.Fill(myds);
this.GridView1.DataSource = myds;
this.GridView1.DataBind();
}
catch (Exception error)
{
Response.Write("<script>alert('您输入的时间格式有误,请输入****-**-**格式的日期')</script>");
this.TextBoxStartDate.Text = "处理失败!原因为:" + error.ToString();
}
finally
{
//关闭数据库连接
OleDbcon.Close();
}