本文介绍了我的 MS Access 数据库不会更新 asp.net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试更新我的数据库但没有成功.这是我的桌子的样子:
I'm trying to update my database without success. This is how my table looks:
https://i.stack.imgur.com/Q6EDk.png
打开模态后它看起来像这样:
After opening the modal its look like this:
https://i.stack.imgur.com/JusUp.png
所有的表都使用中继器,这是我的代码.
and all the table works with a repeater, this is my code.
protected void Btnupdate_Click(object sender, EventArgs e)
{
try
{
foreach (RepeaterItem RI in rptEdit.Items)
{
Label id = RI.FindControl("Pid") as Label;
TextBox prdname = RI.FindControl("prdname") as TextBox;
TextBox prdprice = RI.FindControl("prdprice") as TextBox;
TextBox prdshortdesc = RI.FindControl("prdshortdesc") as TextBox;
TextBox prdtype = RI.FindControl("prdtype") as TextBox;
TextBox prdbrand = RI.FindControl("prdbrand") as TextBox;
Literal ltl = RI.FindControl("ltlmsg") as Literal;
string ConnString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\Table.accdb";
string SqlString = "UPDATE ProductList SET Pname = ?";
using (OleDbConnection conn = new OleDbConnection(ConnString))
{
using (OleDbCommand cmd = new OleDbCommand(SqlString, conn))
{
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("Pname", prdname.Text);
conn.Open();
cmd.ExecuteNonQuery();
ltl.Text = "<br/>Done.";
}
}
}
}
catch (OleDbException ex)
{
foreach (RepeaterItem RI in rptEdit.Items)
{
Literal ltl = RI.FindControl("ltlmsg") as Literal;
ltl.Text = ex.Message;
}
}
}
当我点击更新按钮时,它正在刷新但没有任何反应.
When I click the update button, it's refreshing but nothing happens.
请帮忙.
推荐答案
you just check your update query:
string SqlString = "UPDATE ProductList SET Pname = ?";
change to this:
string SqlString = "UPDATE ProductList SET Pname =@Pname ";
and change command parameter to pass scaler variable:
cmd.Parameters.AddWithValue("@Pname", prdname.Text);
这篇关于我的 MS Access 数据库不会更新 asp.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!