vijay VAISHNAV

vijay VAISHNAV

  • 1.9k
  • 34
  • 157

An unhandled exception of type 'System.Data.OleDb.OleDbExcep

Feb 27 2020 3:27 AM
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
so please help me resolve this Problam
my code is here:
i have two table in my database first CUSTOMER and second MONTHLYINSTALLMENT 
 
 
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();
}
catch (ApplicationException ex)
{
MessageBox.Show("Error:" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void SaveRecord()
{
String connstring = ConfigurationManager.ConnectionStrings["FincorpData"].ConnectionString;
string cmdstring = "INSERT INTO CUSTOMER (LoanNumber, LoanDate, CustomerName, Father'sName, Address, MobileNo, SecMobileNo, City, District, State) VALUES (@LoanNumber, @LoanDate, @CustomerName, @Father'sName, @Address, @MobileNo, @SecMobileNo, @City, @District, @State) INSERT INTO MONTHLYINSTALLMENT (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("@LoanNumber", textBoxLoanNumber.Text);
cmd.Parameters.AddWithValue("@LoanDate", textBoxLoanDate.Text);
cmd.Parameters.AddWithValue("@CustomerName", txtCustomerName.Text);
cmd.Parameters.AddWithValue("@Father'sName", 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.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();
MessageBox.Show("Recourd is saved", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
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 Select Loan Amount in Loan Details Tab", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
txtPrice.Focus();
return false;
}
if (txtDownPayment.Text.Trim() == string.Empty)
{
MessageBox.Show("Down Payment is Requied", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
txtDownPayment.Focus();
return false;
}
if (txtFileCharge.Text.Trim() == string.Empty)
{
MessageBox.Show("File Charge is Requied", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
txtFileCharge.Focus();
return false;
}
if (txtMonth.Text.Trim() == string.Empty)
{
MessageBox.Show("Month is Requied", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
txtMonth.Focus();
return false;
}
if (txtInterest.Text.Trim() == string.Empty)
{
MessageBox.Show("Interest Rate is Requied", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
txtInterest.Focus();
return false;
}
return true;
}
}
}
 

Answers (2)