在查询时在BOX1和TEXTBOX2中输入起始时间,点击BUTTON按钮查询,这是语句,string beginTime =TextBox1.Text.ToString();
string endTime =TextBox2.Text.ToString();
SqlDataAdapter sqlAdapter = new SqlDataAdapter("select * from CardRecord where convert(varchar(10),date,112) between beginTime=" + TextBox1.Text + " and endTime)", sqlCon);
sqlAdapter.Fill(ds);
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();
其中 sqlAdapter.Fill(ds);这个语句老是出错,为什么
,求改正,我是新手
搞不懂了数据库存放的时间段是这样的:2011-7-3 19:02 。通过 convert(varchar(10),date,112)变成20110703,然后和TEXTBOX1和textBOX2 控件中输入的内容比较时间段,然后进行查询
追答问你字段的信息呀。是什么呢?比如:CreateTime datetime
追问MEAL_TIME
追答"select * from CardRecord where MEAL_TIME between '" + beginTime+ "' and '" +endTime+ "')",
这样OK啦,时间比较无需任何转化!!
sqlAdapter.Fill(ds);错误还是处在这个地方
追答你这个是啥语言啊,试试看这句
SqlDataAdapter sqlAdapter = new SqlDataAdapter("select * from CardRecord where MEAL_TIME between '" + begintime+ '" and '" + endtime + "')", sqlCon);
在 SQL里面是字符串表示时间是要加上单引号的 ,你要在begintime和endtime的前后加上单引号