I am trying to create a sign-up for our movie database. I am trying to establish a connection from the MS Access that we made. But whenever I run my code, I get an error. I am using Visual Studio Express 2012 C#.
Why does my code trigger this error?
"An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in System.Data.dll Additional information: Syntax error in INSERT INTO statement."
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;
namespace BigScreen
{
public partial class sign_up : Form
{
private OleDbConnection connection = new OleDbConnection();
public sign_up()
{
InitializeComponent();
}
private void sign_up_Load(object sender, EventArgs e)
{
connection.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\raizel\Desktop\DataBase\Movie_Database.accdb;
Persist Security Info=False;";
}
private void sign_up_FormClosed(object sender, FormClosedEventArgs e)
{
Form1 thisform = new Form1();
thisform.Show();
}
}
private void button1_Click(object sender, EventArgs e)
{
connection.Open();
OleDbCommand command = new OleDbCommand();
command.Connection = connection;
command.CommandText = "Insert into User ([firstname], [lastname], [username], [password]) values ('" + textBox2.Text + "','" + textBox5.Text + "','" + textBox4.Text + "','" + textBox1.Text + "')";
command.ExecuteNonQuery();
userID++;
MessageBox.Show("Data Saved!");
connection.Close();
}
}
}