如何解决Visual Studio 数据库未更新
我正在处理一个学校项目,由于某种原因,尽管更改的行数不超过 0 并触发更新成功警报,但我的 mysql 数据库没有更新。它还设法仅从我的文件上传更新我的图像数据。
**admin_products_details_edit.aspx.cs**
protected void btn_ProdEdit_Click(object sender,EventArgs e)
{
int result = 0;
string image = "";
if (FileUpload_ProdImg.HasFile == true)
{
image = "images\\" + FileUpload_ProdImg.FileName;
img_result.ImageUrl = FileUpload_ProdImg.FileName;
}
else
{
image = img_result.ImageUrl;
}
Product Prod = new Product();
string datProdID = lbl_ProdID.Text;
string datProdName = tb_ProdName.Text;
string datProdDesc = tb_ProdDesc.Text;
string datProdImg = img_result.ImageUrl;
decimal datProdPrice = decimal.Parse(tb_ProdPrice.Text);
int datProdCal = int.Parse(tb_ProdCal.Text);
int datStockLvl = int.Parse(tb_StockLvl.Text);
result = Prod.ProductUpdate(datProdID,datProdName,datProdDesc,datProdImg,datProdPrice,datProdCal,datStockLvl);
if (result > 0)
{
string saveimg = Server.MapPath(" ") + "\\" + image;
FileUpload_ProdImg.SaveAs(saveimg);
Response.Write("<script>alert('Update successful');</script>");
Response.Redirect("admin_products_details.aspx?ProdID=" + datProdID);
}
else
{
Response.Write("<script>alert('Update fail');</script>");
}
}<-The code for the button edit event trigger
**Product.cs**
...public int ProductUpdate(string upID,string upName,string upDesc,string upImg,decimal upPrice,int upCal,int upstkLvl)
{
string queryStr = "UPDATE Products SET" + " ProdName = @productName," + " ProdDesc = @productDesc," + " ProdImg = @productImage," + " ProdPrice = @productPrice," + " ProdCalorie = @productCal," + " StockLevel = @productStkLvl " + " WHERE ProdID = @productID";
SqlConnection conn = new SqlConnection(_connStr);
SqlCommand cmd = new SqlCommand(queryStr,conn);
cmd.Parameters.AddWithValue("@productID",upID);
cmd.Parameters.AddWithValue("@productName",upName);
cmd.Parameters.AddWithValue("@productDesc",upDesc);
cmd.Parameters.AddWithValue("@productImage",upImg);
cmd.Parameters.AddWithValue("@productPrice",upPrice);
cmd.Parameters.AddWithValue("@productCal",upCal);
cmd.Parameters.AddWithValue("@productStkLvl",upstkLvl);
conn.Open();
int nofRow = 0;
nofRow = cmd.ExecuteNonQuery();
conn.Close();
return nofRow;
}<-The code for updating the mysql database,located in a different cs file,titled Product.cs
我的mysql数据库表叫做Products
非常感谢您提前提供帮助。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。