问题描述
- c#调试程序时有时间变量,显示语法错误 (操作符丢失)
-
在vs2010中用c#调试程序时涉及到时间变量,结果报错,操作符丢失,代码如下,求高手指点
DateTime dd = System.DateTime.Now;
DateTime sjq;
DateTime sjz;
//时间起默认值:当月第一天0点
sjq = Convert.ToDateTime(dd.Year.ToString() + "-" + dd.Month.ToString() + "-" + dd.Day.ToString() + " 00:00:00");//时间止默认值:当天时间24点 sjz = Convert.ToDateTime(dd.Year.ToString() + "-" + dd.Month.ToString() + "-" + dd.Day.ToString() + " 23:59:59"); this.mTGL_C_KPXXTableAdapter.FillBy_DTKPXX(this.xszmkj.MTGL_C_KPXX,sjq,sjz); //下面这一句报错 DataSet odr1 = Microsoft.ApplicationBlocks.Data.AccessHelper.ExecuteDataset(Access_con, CommandType.Text, "select MAX(XSDJ) from mTGL_C_KPXX where LRRQ BETWEEN ‘" + sjq + "’ AND ‘" + sjz + "’"); string zgxsdj = odr1.Tables[0].Rows[0]["XSDJ"].ToString(); label12.Text = zgxsdj+"元";
解决方案
是你的sql语句有问题吧,你还是把整个sql打印出来,看看具体内容,放到数据库中查询看看哪有问题
解决方案二:
sql语法错误,时间要加单引号
即 "select MAX(XSDJ) from mTGL_C_KPXX where LRRQ BETWEEN " + sjq + " AND " + sjz + "");
string zgxsdj = odr1.Tables[0].Rows[0]["XSDJ"].ToString();
改为
"select MAX(XSDJ) from mTGL_C_KPXX where LRRQ BETWEEN '" + sjq + "' AND '" + sjz + "'");
string zgxsdj = odr1.Tables[0].Rows[0]["XSDJ"].ToString();
解决方案三:
棒棒哒嗯呐。我用的是VS2013
时间: 2024-11-01 09:04:36