TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
vijay VAISHNAV
NA
199
2.5k
An unhandled exception of type System.Data.OleDb.OleDbExcep
Feb 29 2020 2:41 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 Only in First Table Data Save successfully But in Second Table D
ata 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
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
;
}
}
}
Reply
Answers (
2
)
anonymous method
Csharp method does not save or return any value eventhough