我要实现表里某个字段值减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();
代码如下:
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();
string updateStr = "update zhuanjia set [xh] ='"+xh+"' where [id] = " + Convert.ToInt32(Request["id"]);
string updateStr = "update zhuanjia set [xh] = '"+xx+"' where [id]
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();
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();
防止为空
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();