Click here to Skip to main content
14,695,439 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Error Show

An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in System.Data.dll
Additional information: Syntax error in INSERT INTO statement

What I have tried:

private void LoanDetails()
   foreach (DataGridViewRow row in dataGridView1.Rows)
      String connstring = ConfigurationManager.ConnectionStrings["FincorpData"].ConnectionString;
      string cmdstring = "insert into installment (InstallmentNumber, LoanNumber, InstallmentDate, LoanAmount, PaymentStatus,) VALUES (@InstallmentNumber, @LoanNumber3, @InstallmentDate, @LoanAmount, @PaymentStatus)";

      using (OleDbConnection con = new OleDbConnection(connstring))
         using (OleDbCommand cmd = new OleDbCommand(cmdstring, con))

            cmd.Parameters.AddWithValue("@InstallmentNumber", row.Cells["SrNo"].Value);
            cmd.Parameters.AddWithValue("@LoanNumber3", row.Cells["LoanNumber"].Value);
            cmd.Parameters.AddWithValue("@InstallmentDate", row.Cells["Date"].Value);
            cmd.Parameters.AddWithValue("@LoanAmount", row.Cells["Installment"].Value);
            cmd.Parameters.AddWithValue("@PaymentStatus", row.Cells["Status"].Value);

Updated 7-Mar-20 4:01am

1 solution

There is an extra comma after "Insert into ...PaymentStatus,)
Amar chand123 7-Mar-20 9:34am
Thank You

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900