我的 MS Access 数据库不会更新 asp.net

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

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
how do i pass parameters to aspnet reportviewer(如何将参数传递给aspnet report查看器)
Bind multiple parameters from route and body to a model in ASP.NET Core(在ASP.NET Core中将路由和主体中的多个参数绑定到一个模型)
Custom model binding in AspNet Core WebApi?(AspNet Core WebApi中的自定义模型绑定?)
How to minify in .net core mvc view?(如何在.Net核心MVC视图中缩小?)