2 wxb1217003953 wxb1217003953 于 2015.06.30 17:06 提问

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+"元";

3个回答

bdmh
bdmh   Ds   Rxr 2015.06.30 17:10

是你的sql语句有问题吧,你还是把整个sql打印出来,看看具体内容,放到数据库中查询看看哪有问题

wxb1217003953
wxb1217003953 是这一句的问题 DataSet odr1 = Microsoft.ApplicationBlocks.Data.AccessHelper.ExecuteDataset(Access_con, CommandType.Text, "select MAX(XSDJ) from mTGL_C_KPXX where LRRQ BETWEEN " + sjq + " AND " + sjz + "");
2 年多之前 回复
krepute
krepute   2015.06.30 18:03

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();

wxb1217003953
wxb1217003953 改过来了,报错:标准表达式中的数据类型不匹配
2 年多之前 回复
shskd
shskd   2016.03.20 08:12

棒棒哒嗯呐。我用的是VS2013

Csdn user default icon
上传中...
上传图片
插入图片