1

I used this code for so long with no problem. However, right now as I try to insert into the database, I get this error

ERROR [07002] [MICROSOFT] ODBC MICROSOFT ACCESS DRIVER] TOO FEW PARAMETERS EXPECTED 2.

Can someone let me know what I am doing wrong?

if (txtFullName.Text == "" || txtPostcode.Text == "")
{
    MessageBox.Show("Please enter appropriate details in order to proceed", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else if (txtFullName.Text != "" && txtFullName.Text != "")
{
    OdbcCommand cmd = new OdbcCommand("INSERT INTO [Entry] ([FullName], Postcode) Values(@A, @B)", ConnectDb);
    cmd.Parameters.AddWithValue("@A", "HI");
    cmd.Parameters.AddWithValue("@B", "BY");

    ConnectDb.Open();

    try
    {
        int res = cmd.ExecuteNonQuery();

        if (res > 0)
        {
           DialogResult dialogResult = MessageBox.Show("New Allocator saved! would you like to exit? ", "Saved", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

           if (dialogResult == DialogResult.Yes)
           {
               //BackToAdminMainMenu();
           }

           if (dialogResult == DialogResult.No)
           {
               //Clear();
           }
       }
   }
   catch (Exception err)
   {
       MessageBox.Show("A database error has occurred: " + Environment.NewLine + err.Message);
   }
   finally
   {
       ConnectDb.Close();
   }
}
Cœur
  • 37,241
  • 25
  • 195
  • 267
Tim Jones
  • 63
  • 1
  • 10

1 Answers1

3

ODBC doesn't support named parameters. Try using:

"INSERT INTO [Entry] ([FullName], Postcode) Values(?, ?)"

instead

Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900