My MS Access database won#39;t update asp.net(我的 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:我的 MS Access 数据库不会更新 asp.net


- 如何用自己压缩一个 IEnumerable 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- 输入按键事件处理程序 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01