Hi everyone, pls help me with my problem. I got error (OleDbException was unhandled) (sysntax error in INSERT INTO statement) specifically, the error points out in "int temp = oleDbCmd.ExecuteNonQuery();"
And, here's my code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace sad
{
public partial class SignIn : Form
{
private OleDbConnection personalConn;
private OleDbCommand oleDbCmd = new OleDbCommand();
private String connParam = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\EtaYuy\Documents\Collection22ady1.mdb;Persist Security Info=False";
public SignIn()
{
personalConn = new OleDbConnection(connParam);
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Close();
T frm = new T();
frm.Show();
}
private void button2_Click(object sender, EventArgs e)
{
personalConn.Open();
oleDbCmd.Connection = personalConn;
oleDbCmd.CommandText = "insert into Personal Data (Block No, Lot No,Number of Occupants,First Name,Family Name,Date of Birth,Age, Blood Type, Place of Birth, Religion) values ('" + this.textBox1.Text + "','" + this.textBox2.Text + "','" + this.textBox3.Text + "','" + this.textBox4.Text + "','" + this.textBox5.Text + "','" + this.textBox6.Text + "','" + this.textBox7.Text + "','" + this.textBox8.Text + "','" + this.textBox9.Text + "','" + this.textBox10.Text + "');";
oleDbCmd.CommandText = "insert into Spouse (First Name, Family Name,Date of Birth,Age,Blood Type,Place of Birth, Religion, Start of occupancy, contact number, Name of Children, Number of Occupants, Number of Dogs, Vaccinated with Anti-rabies) values ('" + this.textBox11.Text + "','" + this.textBox12.Text + "','" + this.textBox21.Text + "','" + this.textBox13.Text + "','" + this.textBox14.Text + "','" + this.textBox15.Text + "','" + this.textBox16.Text + "','" + this.textBox17.Text + "','" + this.textBox18.Text + "','" + this.richTextBox1.Text + "','" + this.textBox20.Text + "','" + this.textBox25.Text + "','" + this.textBox19.Text + "');";
** int temp = oleDbCmd.ExecuteNonQuery();** //error here
if (temp > 0)
{
textBox1.Text = null;
textBox2.Text = null;
textBox3.Text = null;
textBox4.Text = null;
textBox5.Text = null;
textBox6.Text = null;
textBox7.Text = null;
textBox8.Text = null;
textBox9.Text = null;
textBox10.Text = null;
textBox11.Text = null;
textBox12.Text = null;
textBox21.Text = null;
textBox13.Text = null;
textBox14.Text = null;
textBox15.Text = null;
textBox16.Text = null;
textBox17.Text = null;
textBox18.Text = null;
richTextBox1.Text = null;
textBox25.Text = null;
textBox19.Text = null;
MessageBox.Show("Record Successfuly Added");
textBox1.Clear();
textBox2.Clear();
textBox3.Clear();
textBox4.Clear();
textBox5.Clear();
textBox6.Clear();
textBox7.Clear();
textBox8.Clear();
textBox9.Clear();
textBox10.Clear();
textBox11.Clear();
textBox12.Clear();
textBox21.Clear();
textBox13.Clear();
textBox14.Clear();
textBox15.Clear();
textBox16.Clear();
textBox17.Clear();
textBox18.Clear();
richTextBox1.Clear();
textBox20.Clear();
textBox25.Clear();
textBox19.Clear();
}
else
{
MessageBox.Show("Record Fail to Added");
}
personalConn.Close();
}
private void SignIn_Load(object sender, EventArgs e)
{
}
I hope you can help me. thank you
}
}
I hope