Having Trouble inserting into Access Database.

The following attachments are:

Capture --> Actual Code
Capture2 ---> Access Database
Capture3 --> Error Message

public string saveTrace(Trace aTrace)
        {
            //get values from Transaction instance
            string traceID = "";
            decimal amount = aTrace.getAmount();
            string transType = aTrace.getTransType();
            string dID = aTrace.getDealerID();
            string dsID = aTrace.getDealershipID();
            string VIN = aTrace.getVIN();
            DateTime date = aTrace.getDate();

             
            OleDbCommand cmd=new OleDbCommand();

            cmd.CommandText = "insert into Trace (DS_ID,D_ID, Trace_Type, T_Amount, T_Date, VIN) values (@DS_ID, @D_ID, @Trace_Type, @T_Amount, @T_Date, @VIN)";
      
           
            cmd.Connection=ConnectionClass.getConnection();

               

            

            cmd.Parameters.AddWithValue("@DS_ID",dsID);

            cmd.Parameters.AddWithValue("@D_ID",dID);

            cmd.Parameters.AddWithValue("@Trace_Type",transType);

            cmd.Parameters.AddWithValue("@T_Amount",amount);
          
            cmd.Parameters.AddWithValue("@T_Date",date);

            cmd.Parameters.AddWithValue("@VIN",VIN);

            cmd.ExecuteNonQuery();

            cmd.Connection.Close();

By the way...this is the best source for IT/Developer questions that I have seen on the internet.

Thanks,

Derek

Attachments Capture2.PNG 17.48 KB Capture3.PNG 45.22 KB Capture.PNG 15.03 KB

IIRC, Access doesn't support @ parameters, you have to use ? and then make sure you add them in order:

cmd.CommandText = "insert into Trace (DS_ID,D_ID, Trace_Type, T_Amount, T_Date, VIN) values (?, ?, ?, ?, ?, ?)";
This article has been dead for over six months. Start a new discussion instead.