gpt4 book ai didi

c# - UPDATE 查询未更新 Access 数据库中的记录

转载 作者:行者123 更新时间:2023-11-29 19:44:54 24 4
gpt4 key购买 nike

任何人都可以看一下我的代码并告诉我出了什么问题吗?我正在尝试更新这些值,但 Access 数据库没有更新,即使我的方法正在解析查询。

protected void Page_Load(object sender, EventArgs e)
{
if ((string)Session["sFlag"] != "LI")
{
Response.Redirect("Default.aspx");
}
else
{
strUserId = (string)Session["sUserId"];
txtUserId.Text = strUserId;
txtName.Text = (string)Session["sName"];
txtAddress.Text = (string)Session["sAddress"];
txtEmail.Text = (string)Session["sEmail"];
txtTel.Text = (string)Session["sContactNo"];


}
}
protected void btnSubmit_Click(object sender, EventArgs e)
{

strUserId = (string)Session["sUserId"];
if (txtName.Text != "")
{
String strFName = "cFullName";
String strFValue = txtName.Text;
UpdateCustomer(strFName, strFValue);
Session["sName"] = txtName.Text;
}
if (UFlag == "T")
{
Type strType = this.GetType();
ClientScript.RegisterStartupScript(strType, "Success", scriptSuccessUpdate);
}


}

public void UpdateCustomer(string strFName, string strFValue)
{
OleDbConnection mDB = new OleDbConnection();
mDB.ConnectionString = "Provider = Microsoft.ACE.OLEDB.12.0;Data source="
+ Server.MapPath("~/App_Data/WMA_Proj.accdb");
mDB.Open();
OleDbCommand cmd;
String strSQL = "UPDATE Customers SET " + strFName +
" = @newValue WHERE cUserId = @userId";
cmd = new OleDbCommand(strSQL, mDB);
cmd.Parameters.Add("@newValue", OleDbType.Char).Value = strFValue;
cmd.Parameters.Add("@userId", OleDbType.Char).Value = strUserId;
cmd.ExecuteNonQuery();
UFlag = "T";
mDB.Close();

}

}

这也是我的 Access 数据库表(图像)。

Access Database Table

最佳答案

试试这个

 public void UpdateCustomer(string strFName, string strFValue)
{
OleDbConnection mDB = new OleDbConnection();
mDB.ConnectionString = "Provider = Microsoft.ACE.OLEDB.12.0;Data source="
+ Server.MapPath("~/App_Data/WMA_Proj.accdb");
mDB.Open();
OleDbCommand cmd;
String strSQL = "UPDATE Customers SET cFullname= @newValue WHERE cUserId = @userId";
cmd = new OleDbCommand(strSQL, mDB);
cmd.Parameters.AddWithValue("@newValue", strFName);
cmd.Parameters.AddWithValue("@userId",strFvalue);
cmd.ExecuteNonQuery();
UFlag = "T";
mDB.Close();

}

关于c# - UPDATE 查询未更新 Access 数据库中的记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41085410/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com