Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in System.Data.dll
Additional information: Syntax error in INSERT INTO statement..


This Error Show when i try save record Only in First Table Data Save successfully But in Second Table Data not Save and Show Error
so please help me resolve this Problam
my code is here:
i have two table in my database first CUSTOMER and second MONTHLYINSTALLMENT

What I have tried:

C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.OleDb;
using System.Configuration;


namespace Fincorp
{
    public partial class NewCustomerEntry : Form
    {
        public NewCustomerEntry()
        {
            InitializeComponent();
        }

        private void NewCustomerEntry_Load(object sender, EventArgs e)
        {
           
        }

        private void textBoxMobileNo_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBoxNetLoanAmt_TextChanged(object sender, EventArgs e)
        {

        }

        private void btnexitCustomerEntry_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnsaveCustomerEntry_Click(object sender, EventArgs e)
        {
            if (IsValidated())
            {
                try
                {
                    SaveRecord(); tabControl1.SelectTab(tabPage2); SaveRecord1();
                    
                }
                catch (ApplicationException ex)
                {
                    MessageBox.Show("Error:" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }

        private void SaveRecord()
        {
            String connstring = ConfigurationManager.ConnectionStrings["vijay"].ConnectionString;
            string cmdstring = "insert into customer (LoanNumber, LoanDate, CustomerName, FatherName, Address, MobileNo, SecMobileNo, City, District, State) VALUES (@LoanNumber, @LoanDate, @CustomerName, @FatherName, @Address, @MobileNo, @SecMobileNo, @City, @District, @State)";
          
            using (OleDbConnection con = new OleDbConnection(connstring))
            {
                using (OleDbCommand cmd = new OleDbCommand(cmdstring, con))
                {
                    con.Open();

                    cmd.Parameters.AddWithValue("@LoanNumber", textBoxLoanNumber.Text);
                    cmd.Parameters.AddWithValue("@LoanDate", textBoxLoanDate.Text);
                    cmd.Parameters.AddWithValue("@CustomerName", txtCustomerName.Text);
                    cmd.Parameters.AddWithValue("@FatherName", txtFatherName.Text);
                    cmd.Parameters.AddWithValue("@Address", txtAddress.Text);
                    cmd.Parameters.AddWithValue("@MobileNo", txtMobileNo.Text);
                    cmd.Parameters.AddWithValue("@SecMobileNo", txtSecMobileno.Text);
                    cmd.Parameters.AddWithValue("@City", txtCity.Text);
                    cmd.Parameters.AddWithValue("@District", txtDistrict.Text);
                    cmd.Parameters.AddWithValue("@State", txtState.Text);
                    
                    cmd.ExecuteNonQuery();
                    MessageBox.Show("Recourd is saved", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    con.Close();
                }   
            }
        }

        private void SaveRecord1()
        {
            tabControl1.SelectTab(tabPage2);
            {
                String connstring = ConfigurationManager.ConnectionStrings["vijay"].ConnectionString;
                string cmdstring = "insert into monthlyinstalment (LoanNumber, Price, DownPayment, FileCharge, Month, Intrest) VALUE (@LoanNumber1, @Price, @DownPayment, @FileCharge, @Month, @Intrest)";

                using (OleDbConnection con = new OleDbConnection(connstring))
                {
                    using (OleDbCommand cmd = new OleDbCommand(cmdstring, con))
                    {
                        con.Open();

                        cmd.Parameters.AddWithValue("@LoanNumber1", textBoxLoanNumber.Text);
                        cmd.Parameters.AddWithValue("@Price", txtPrice.Text);
                        cmd.Parameters.AddWithValue("@DownPayment", txtDownPayment.Text);
                        cmd.Parameters.AddWithValue("@FileCharge", txtFileCharge.Text);
                        cmd.Parameters.AddWithValue("@Month", txtMonth.Text);
                        cmd.Parameters.AddWithValue("@Intrest", txtInterest.Text);

                        cmd.ExecuteNonQuery();
                        con.Close();
                    }
                }
            }
        }

        private bool IsValidated()
        {
           if (txtCustomerName.Text.Trim() == string.Empty)
           {
               MessageBox.Show("Customer Name is Requied", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
               txtCustomerName.Focus();
               return false;
           }

           if (txtFatherName.Text.Trim() == string.Empty)
           {
               MessageBox.Show("Father's Name is Requied", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
               txtFatherName.Focus();
               return false;
           }

           if (txtAddress.Text.Trim() == string.Empty)
           {
               MessageBox.Show("Address is Requied", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
               txtAddress.Focus();
               return false;
           }

           if (txtMobileNo.Text.Trim() == string.Empty)
           {
               MessageBox.Show("Mobile Number is Requied", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
               txtMobileNo.Focus();
               return false;
           }


           if (txtPrice.Text.Trim() == string.Empty)
           {
               MessageBox.Show("Loan Amount is Requied", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
               tabControl1.SelectTab(tabPage2);  txtPrice.Focus();
               return false;
           }

           if (txtDownPayment.Text.Trim() == string.Empty)
           {
               MessageBox.Show("Down Payment is Requied", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
               tabControl1.SelectTab(tabPage2);  txtDownPayment.Focus();
               return false;
           }

           if (txtFileCharge.Text.Trim() == string.Empty)
           {
               MessageBox.Show("File Charge is Requied", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
               tabControl1.SelectTab(tabPage2);  txtFileCharge.Focus();
               return false;
           }
           if (txtMonth.Text.Trim() == string.Empty)
           {
               MessageBox.Show("Month is Requied", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
               tabControl1.SelectTab(tabPage2);  txtMonth.Focus();
               return false;
           }

           if (txtInterest.Text.Trim() == string.Empty)
           {
               MessageBox.Show("Interest Rate is Requied", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
               tabControl1.SelectTab(tabPage2); txtInterest.Focus();
               return false;
           }
            
            return true;
        }
    }
}
Posted
Updated 28-Feb-20 22:09pm
v3
Comments
Richard MacCutchan 29-Feb-20 4:56am    
Most likely something in one of your textboxes is not valid. Use your debugger to check.

1 solution

you seem to be missing S from the VALUES keyword.

Instead of
C#
string cmdstring = "insert into monthlyinstalment (LoanNumber, Price, DownPayment, FileCharge, Month, Intrest) VALUE (@LoanNumber1, @Price, @DownPayment, @FileCharge, @Month, @Intrest)";

use
C#
string cmdstring = "insert into monthlyinstalment (LoanNumber, Price, DownPayment, FileCharge, Month, Intrest) VALUES (@LoanNumber1, @Price, @DownPayment, @FileCharge, @Month, @Intrest)";
 
Share this answer
 
Comments
Amar chand123 29-Feb-20 4:39am    
Wendelius, i change "Value" into "values" But Problem Remaining Same
Wendelius 29-Feb-20 4:43am    
What exception you now get ?

Based on your post should the name of the table be MONTHLYINSTALLMENT instead of MONTHLYINSTALMENT, one L missing perhaps?
Amar chand123 29-Feb-20 4:52am    
Fixed MONTHLYINSTALMENT, but Problem Remaining Same
https://snipboard.io/6h09Vl.jpg
Design View
Wendelius 29-Feb-20 4:54am    
Could you post the error simply as text here. I'm not able to access the site you're referring.
Amar chand123 29-Feb-20 4:56am    
An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in System.Data.dll

Additional information: Syntax error in INSERT INTO statement.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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