vijay VAISHNAV

vijay VAISHNAV

  • NA
  • 199
  • 2.3k

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 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
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.ComponentModel;  
  4. using System.Data;  
  5. using System.Drawing;  
  6. using System.Linq;  
  7. using System.Text;  
  8. using System.Threading.Tasks;  
  9. using System.Windows.Forms;  
  10. using System.Data.OleDb;  
  11. using System.Configuration;  
  12. namespace Fincorp  
  13. {  
  14. public partial class NewCustomerEntry : Form  
  15. {  
  16. public NewCustomerEntry()  
  17. {  
  18. InitializeComponent();  
  19. }  
  20. private void NewCustomerEntry_Load(object sender, EventArgs e)  
  21. {  
  22. }  
  23. private void textBoxMobileNo_TextChanged(object sender, EventArgs e)  
  24. {  
  25. }  
  26. private void textBoxNetLoanAmt_TextChanged(object sender, EventArgs e)  
  27. {  
  28. }  
  29. private void btnexitCustomerEntry_Click(object sender, EventArgs e)  
  30. {  
  31. this.Close();  
  32. }  
  33. private void btnsaveCustomerEntry_Click(object sender, EventArgs e)  
  34. {  
  35. if (IsValidated())  
  36. {  
  37. try  
  38. {  
  39. SaveRecord(); tabControl1.SelectTab(tabPage2); SaveRecord1();  
  40. }  
  41. catch (ApplicationException ex)  
  42. {  
  43. MessageBox.Show("Error:" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);  
  44. }  
  45. }  
  46. }  
  47. private void SaveRecord()  
  48. {  
  49. String connstring = ConfigurationManager.ConnectionStrings["vijay"].ConnectionString;  
  50. 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)";  
  51. using (OleDbConnection con = new OleDbConnection(connstring))  
  52. {  
  53. using (OleDbCommand cmd = new OleDbCommand(cmdstring, con))  
  54. {  
  55. con.Open();  
  56. cmd.Parameters.AddWithValue("@LoanNumber", textBoxLoanNumber.Text);  
  57. cmd.Parameters.AddWithValue("@LoanDate", textBoxLoanDate.Text);  
  58. cmd.Parameters.AddWithValue("@CustomerName", txtCustomerName.Text);  
  59. cmd.Parameters.AddWithValue("@FatherName", txtFatherName.Text);  
  60. cmd.Parameters.AddWithValue("@Address", txtAddress.Text);  
  61. cmd.Parameters.AddWithValue("@MobileNo", txtMobileNo.Text);  
  62. cmd.Parameters.AddWithValue("@SecMobileNo", txtSecMobileno.Text);  
  63. cmd.Parameters.AddWithValue("@City", txtCity.Text);  
  64. cmd.Parameters.AddWithValue("@District", txtDistrict.Text);  
  65. cmd.Parameters.AddWithValue("@State", txtState.Text);  
  66. cmd.ExecuteNonQuery();  
  67. MessageBox.Show("Recourd is saved""Success", MessageBoxButtons.OK, MessageBoxIcon.Information);  
  68. con.Close();  
  69. }  
  70. }  
  71. }  
  72. private void SaveRecord1()  
  73. {  
  74. tabControl1.SelectTab(tabPage2);  
  75. {  
  76. String connstring = ConfigurationManager.ConnectionStrings["vijay"].ConnectionString;  
  77. string cmdstring = "insert into monthlyinstalment (LoanNumber, Price, DownPayment, FileCharge, Month, Intrest) VALUE (@LoanNumber1, @Price, @DownPayment, @FileCharge, @Month, @Intrest)";  
  78. using (OleDbConnection con = new OleDbConnection(connstring))  
  79. {  
  80. using (OleDbCommand cmd = new OleDbCommand(cmdstring, con))  
  81. {  
  82. con.Open();  
  83. cmd.Parameters.AddWithValue("@LoanNumber1", textBoxLoanNumber.Text);  
  84. cmd.Parameters.AddWithValue("@Price", txtPrice.Text);  
  85. cmd.Parameters.AddWithValue("@DownPayment", txtDownPayment.Text);  
  86. cmd.Parameters.AddWithValue("@FileCharge", txtFileCharge.Text);  
  87. cmd.Parameters.AddWithValue("@Month", txtMonth.Text);  
  88. cmd.Parameters.AddWithValue("@Intrest", txtInterest.Text);  
  89. cmd.ExecuteNonQuery();  
  90. con.Close();  
  91. }  
  92. }  
  93. }  
  94. }  
  95. private bool IsValidated()  
  96. {  
  97. if (txtCustomerName.Text.Trim() == string.Empty)  
  98. {  
  99. MessageBox.Show("Customer Name is Requied""Error", MessageBoxButtons.OK, MessageBoxIcon.Error);  
  100. txtCustomerName.Focus();  
  101. return false;  
  102. }  
  103. if (txtFatherName.Text.Trim() == string.Empty)  
  104. {  
  105. MessageBox.Show("Father's Name is Requied""Error", MessageBoxButtons.OK, MessageBoxIcon.Error);  
  106. txtFatherName.Focus();  
  107. return false;  
  108. }  
  109. if (txtAddress.Text.Trim() == string.Empty)  
  110. {  
  111. MessageBox.Show("Address is Requied""Error", MessageBoxButtons.OK, MessageBoxIcon.Error);  
  112. txtAddress.Focus();  
  113. return false;  
  114. }  
  115. if (txtMobileNo.Text.Trim() == string.Empty)  
  116. {  
  117. MessageBox.Show("Mobile Number is Requied""Error", MessageBoxButtons.OK, MessageBoxIcon.Error);  
  118. txtMobileNo.Focus();  
  119. return false;  
  120. }  
  121. if (txtPrice.Text.Trim() == string.Empty)  
  122. {  
  123. MessageBox.Show("Loan Amount is Requied""Error", MessageBoxButtons.OK, MessageBoxIcon.Error);  
  124. tabControl1.SelectTab(tabPage2); txtPrice.Focus();  
  125. return false;  
  126. }  
  127. if (txtDownPayment.Text.Trim() == string.Empty)  
  128. {  
  129. MessageBox.Show("Down Payment is Requied""Error", MessageBoxButtons.OK, MessageBoxIcon.Error);  
  130. tabControl1.SelectTab(tabPage2); txtDownPayment.Focus();  
  131. return false;  
  132. }  
  133. if (txtFileCharge.Text.Trim() == string.Empty)  
  134. {  
  135. MessageBox.Show("File Charge is Requied""Error", MessageBoxButtons.OK, MessageBoxIcon.Error);  
  136. tabControl1.SelectTab(tabPage2); txtFileCharge.Focus();  
  137. return false;  
  138. }  
  139. if (txtMonth.Text.Trim() == string.Empty)  
  140. {  
  141. MessageBox.Show("Month is Requied""Error", MessageBoxButtons.OK, MessageBoxIcon.Error);  
  142. tabControl1.SelectTab(tabPage2); txtMonth.Focus();  
  143. return false;  
  144. }  
  145. if (txtInterest.Text.Trim() == string.Empty)  
  146. {  
  147. MessageBox.Show("Interest Rate is Requied""Error", MessageBoxButtons.OK, MessageBoxIcon.Error);  
  148. tabControl1.SelectTab(tabPage2); txtInterest.Focus();  
  149. return false;  
  150. }  
  151. return true;  
  152. }  
  153. }  
  154. }  

Answers (2)