Quantcast
Channel: Visual Studio and Visual Web Developer Express
Viewing all articles
Browse latest Browse all 3509

OleDbException was unhandled by user code...

$
0
0

my specific error is:

the number of query values and destination fields did not match.

I have an Access Database with fields:

Cust_ID

contact

Entry_Date

IP_Address

The Cust_ID is supposed to just be an auto generated primary key number and I know that is where the problem lies, because I am not sure how to implement that in the code:

protected void btn_submit_Click(object sender, EventArgs e)
        {
            string contact = txt_name.Text;
            string IP_Address = Label3.Text;
            DateTime Entry_Date = DateTime.Now;

            string connect = "Provider=Microsoft.Jet.OleDb.4.0;Data Source=|DataDirectory|fbill_system_use.mdb";
            string SqlString = "Insert Into CustRecords (contact, Entry_Date, IP_Address) Values (?,?)";
            using (OleDbConnection conn = new OleDbConnection(connect))
            {

            using (OleDbCommand cmd = new OleDbCommand(SqlString, conn))
  {
                cmd.CommandType = CommandType.Text;
                
                cmd.Parameters.AddWithValue("contact", txt_name.Text);
                cmd.Parameters.AddWithValue("Entry_Date", DateTime.Now);
                cmd.Parameters.AddWithValue("IP_Address", Label3.Text);
                conn.Open();
                cmd.ExecuteNonQuery();
  }
}

I know the CUST_ID field is not in there, How do I implement this, or why the Exception?


Viewing all articles
Browse latest Browse all 3509

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>