我要实现表里某个字段值减1,SQL语句该怎么写?
代码如下:
 OleDbConnection conn = new OleDbConnection();
        conn.ConnectionString = "Provider = Microsoft.Jet.OleDb.4.0;" + "Data Source =" + Server.MapPath("**.mdb");
        string updateStr = "update zhuanjia set [xh] = '"+xh-1+"' where [id] = " + Convert.ToInt32(Request["id"]);        OleDbCommand insCom = new OleDbCommand(updateStr, conn);        conn.Open();        insCom.ExecuteNonQuery();
        conn.Close();

解决方案 »

  1.   

    update zhuanjia set [xh] = xh-1直接写。
      

  2.   

    string updateStr = "update zhuanjia set [xh] =xh-1  where [id] = " + Convert.ToInt32(Request["id"]);xh=xh-1
    string updateStr = "update zhuanjia set [xh] ='"+xh+"'  where [id] = " + Convert.ToInt32(Request["id"]);
      

  3.   

    直接set [xh]=xh-1 就是了
      

  4.   

    string xx=(xh-1).Tostring();
    string updateStr = "update zhuanjia set [xh] = '"+xx+"' where [id] 
      

  5.   

    我如果先要对XH做一下判断,那字段XH该怎么取出来呢? OleDbConnection conn = new OleDbConnection();
            conn.ConnectionString = "Provider = Microsoft.Jet.OleDb.4.0;" + "Data Source =" + Server.MapPath("**.mdb");
    sting xh;
    if()
    {????}
            string updateStr = "update zhuanjia set [xh] = xh-1 where [id] = " + Convert.ToInt32(Request["id"]);        OleDbCommand insCom = new OleDbCommand(updateStr, conn);        conn.Open();        insCom.ExecuteNonQuery();
            conn.Close();
      

  6.   

    我如果先要对XH做一下判断,那字段XH该怎么取出来呢? 大家帮忙看看! OleDbConnection conn = new OleDbConnection();
            conn.ConnectionString = "Provider = Microsoft.Jet.OleDb.4.0;" + "Data Source =" + Server.MapPath("**.mdb");
    sting xh;
    if()
    {????}
            string updateStr = "update zhuanjia set [xh] = xh-1 where [id] = " + Convert.ToInt32(Request["id"]);        OleDbCommand insCom = new OleDbCommand(updateStr, conn);        conn.Open();        insCom.ExecuteNonQuery();
            conn.Close();
      

  7.   

    set [xh]=ISNULL(xh,0)-1
    防止为空
      

  8.   

    OleDbConnection conn = new OleDbConnection();
            conn.ConnectionString = "Provider = Microsoft.Jet.OleDb.4.0;" + "Data Source =" + Server.MapPath("**.mdb");
    sting xh;
    if()
    {????}
            string updateStr = "update zhuanjia set [xh] = xh-1 where [id] = " + Convert.ToInt32(Request["id"]);        OleDbCommand insCom = new OleDbCommand(updateStr, conn);        conn.Open();        insCom.ExecuteNonQuery();
            conn.Close();
      

  9.   

    这位大哥这个判断加在SQL语句上总不是一回事,还是把字段XH取出来判断一下,写一个对话框,方便用户才是了,就是怎么取出来啊,数据库也已经连上了