利用SqlCommand命令实现对数据库的更新问题
我利用SqlCommand命令实现对数据库的数据在原来的基础上加上刚添加的数据实现其更新但
string ConnString = System.Configuration.ConfigurationSettings.AppSettings["SQLCONNECTIONSTRING"];
SqlConnection sqlcon = new SqlConnection(ConnString);
SqlDataAdapter sqld = new SqlDataAdapter("select * from entermx where entergoodsid =" + Convert.ToInt32(Session["entergoodsid"]), sqlcon);
DataSet ds = new DataSet();
sqld.Fill(ds,"table");
dr = ds.Tables["table"].Rows[0];
// int a =Convert.ToInt32(dr["pronum"].ToString());
//创建UPDATE命令字符串
string updatecmd = "update stock set pronum=@pronum where proid="+dr["proid"];
SqlCommand MyCommand = new SqlCommand(updatecmd,sqlcon);
MyCommand.Parameters .Add(new SqlParameter("@pronum",SqlDbType.Int,4));
MyCommand.Parameters["@pronum"].Value +=dr["pronum"].ToString();
MyCommand.Connection .Open();
MyCommand.ExecuteNonQuery();
Response.Write("<script>alert('更新成功!')</Script>");
MyCommand.Connection .Close();