My MS Access database won't update 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.

Please help.

Here is Solutions:

We have many solutions to this problem, But we recommend you to use the first solution because it is tested & true solution that will 100% work for you.

Solution 1

you just check your update query:
string SqlString = "UPDATE ProductList SET Pname = ?";

change to this:
string SqlString = "UPDATE ProductList SET Pname [email protected] ";

and change command parameter to pass scaler variable:
 cmd.Parameters.AddWithValue("@Pname", prdname.Text);

Note: Use and implement solution 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply