简体   繁体   中英

Database update error No Value given for one or more required parameters

I was trying to use the update command to update my database at ms access and there is an error of No Value given for one or more required parameters whenever i try to execute it.

This is my code

private void btnupdate_Click_1(object sender, EventArgs e)
    {
        OleDbConnection con = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=ShopRecords.accdb");
        OleDbDataAdapter ad = new OleDbDataAdapter();
        try
        {
            ad.UpdateCommand = new OleDbCommand("UPDATE ShopRecords SET ProductDescription = '" +tbproductdescrip.Text + "' WHERE (ID= " + tbupdate.Text + ")", con);

            con.Open();
            ad.UpdateCommand.ExecuteNonQuery();
            con.Close();
        }
         catch(Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
    }

try following the next structure:

try
    {
        using (OleDbConnection con = new OleDbConnection(cs))
        {
            con.Open();
            OleDbTransaction tran = con.BeginTransaction();
            OleDbCommand cmd = new OleDbCommand("UPDATE ... SET ... WHERE ...", con);
            cmd.Transaction = tran;
            cmd.ExecuteNonQuery();
            tran.Commit();
            con.Close();
        }
    }
    catch (OleDbException ex)
    {
        Console.WriteLine(ex);
    }

also, a good example: http://msdn.microsoft.com/en-us/library/system.data.oledb.oledbtransaction.commit%28v=vs.110%29.aspx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM