I have been trying to figure out why my program keeps giving me error. system.data.oledb.oledbexception(0x80040E14): Syntax error in INSERT INTO statement.
- Table name:
User
Columns:
Username AccountNumber FirstName LastName
Code:
namespace Library_System
{
public partial class CreateAccountWindow : Form
{
OleDbConnection connect = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Jc\Documents\Visual Studio 2013\Projects\Library System\Library System\LibrarySystemDatabase.accdb;Persist Security Info=False;");
OleDbCommand command = new OleDbCommand();
//OleDbDataReader reader;
public CreateAccountWindow()
{
InitializeComponent();
}
private void button2_Click(object sender, EventArgs e)
{
string Username = "", AccountNumber = "", FirstName = "", LastName = "";
//int Borrowed = 0;
bool hasValue1 = false, hasValue2 = false, hasValue3 = false, hasValue4 = false;
if (textBox1.Text != "")
{
label1.Hide();
Username = textBox1.Text;
hasValue1 = true;
}
else
{
label1.Show();
label1.Text = "Required";
}
if (textBox10.Text != "")
{
label21.Hide();
AccountNumber = textBox8.Text;
hasValue2 = true;
}
else
{
label21.Show();
label21.Text = "Required";
}
if (textBox8.Text != "")
{
label13.Hide();
FirstName = textBox10.Text;
hasValue3 = true;
}
else
{
label13.Show();
label13.Text = "Required";
}
if (textBox7.Text != "")
{
label12.Hide();
label12.Text = "Required";
LastName = textBox7.Text;
hasValue4 = true;
}
else
{
label12.Show();
label12.Text = "Required";
}
if (hasValue1 || hasValue2 || hasValue3 || hasValue4)
{
try
{
connect.Open();
OleDbCommand command = new OleDbCommand();
command.Connection = connect;
command.CommandText = "insert into User (Username,AccountNumber,FirstName,LastName) values ('" + Username + "','" + AccountNumber + "','" + FirstName + "','" + LastName + "')";
command.ExecuteNonQuery();
MessageBox.Show("REGISTRATION COMPLETE !!", "DONE");
connect.Close();
}
catch (Exception ex)
{
connect.Close();
MessageBox.Show("Error:"+ex.ToString());
}
}
}
}