Click here to Skip to main content
15,895,606 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:

C#
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))
         {
            con.Open();

            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);

            cmd.ExecuteNonQuery();
            con.Close();
         }
      }
   }
}
Posted
Updated 7-Mar-20 3:01am
v2

1 solution

There is an extra comma after "Insert into ...PaymentStatus,)
 
Share this answer
 
Comments
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