Here is my code
namespace SDD_Single_Project___Michael
{
public partial class NewUser : Form
{
private OleDbConnection connection = new OleDbConnection();
public NewUser()
{
InitializeComponent();
connection.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=G:\schoolwork\Year 11\SDD\3 SINGLE TASK\SDD Single Project - Michael \SDD Single Project - Michael \bin\Persondata.accdb;
Persist Security Info=False;";
}
private void btnBack_Click(object sender, EventArgs e)
{
this.Hide(); //hides this page
MainScreen frm = new MainScreen(); //finds the next screen (the main game)
frm.Show(); //shows it
}
private void btnSubmit_Click(object sender, EventArgs e)
{
try {
connection.Open(); // opens the connection
OleDbCommand command = new OleDbCommand();
command.Connection = connection;
command.CommandText = "insert into Persondata where ( FirstName,LastName,Address,Suburb,Email,Mobile) values ( '" + txtFirst.Text + "' , '" + txtLast.Text + "' , '" + txtAddress.Text + "' , '" + txtSuburb.Text + "' , '" + txtEmail.Text + "' , '" + txtMobile.Text + "' ) ";
// finds where its going to, finds the columns it is going to fill, finds the text boxes that is going to fill them
command.ExecuteNonQuery(); // error occurs here!!!
MessageBox.Show("Data Saved");
connection.Close(); // closes the connection
}
catch (Exception ex)
{
MessageBox.Show("Error " + ex);
} //if there is a error message box will appear informing it
}
}
}
The error is occurring at the command.ExecuteNonQuery();
and nothing I can do will fix it, the error happens once I fill in all the information into the textboxes and press the submit button.
The error says it is a syntax error in INSERT INTO
statement at
System.Data.Ole.DbCommand.ExecuteNonQuery();
Please help! It's for an assignment! I've been trying to solve it forever. All help is appreciated.