我的MS Access数据库无法更新asp.net

时间:2018-05-27 17:18:35

标签: asp.net webforms

我试图更新我的数据库但没有成功。这就是我的表格:

https://i.stack.imgur.com/Q6EDk.png

打开模态之后,它看起来像这样:

https://i.stack.imgur.com/JusUp.png

并且所有表都与转发器一起使用,这是我的代码。

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;
        }
    }
}

当我点击更新按钮时,它会令人耳目一新但没有任何反应。

请帮忙。

1 个答案:

答案 0 :(得分:0)

var httpRequestFeature = context.Features[typeof(IHttpRequestFeature)] as IHttpRequestFeature;
var path = httpRequestFeature?.Path;