K
kirk g
When I run the following code:
OleDbConnection conn = new OleDbConnection(
@"Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\moneymakin.mdb");
String stmt = "INSERT INTO Person (FirstName,
LastName, Email, LoginID, Password) VALUES (" +
"'" + this.m_perFirstName + "', '" +
this.m_perLastName +
"', '" + this.m_emailAddress + "', '" +
this.m_loginID +
"', '" + this.m_password + "')";
MessageBox.Show(stmt);
//conn.Open();
OleDbCommand perCommand = new OleDbCommand
(stmt, conn);
perCommand.Connection.Open();
perCommand.ExecuteNonQuery();
//OleDbDataReader perReader =
perCommand.ExecuteNonQuery();
//perReader.Close();
I get the following error no matter what:
************** Exception Text **************
System.Data.OleDb.OleDbException: Syntax error in INSERT
INTO statement.
at
System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHand
ling(Int32 hr)
at
System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingle
Result(tagDBPARAMS dbParams, Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteCommandText
(Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteCommand
(CommandBehavior behavior, Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal
(CommandBehavior behavior, String method)
at System.Data.OleDb.OleDbCommand.ExecuteNonQuery()
at WindowsSample.Person.saveNewData() in c:\Documents
and Settings\Kirk Gray\My Documents\Borland Studio
Projects\WindowsSample\DataItems\Person.cs:line 192
at WindowsSample.PersonalInfo.btnPersonalSave_Click
(Object sender, EventArgs e) in c:\Documents and
Settings\Kirk Gray\My Documents\Borland Studio
Projects\WindowsSample\Forms\PersonalInfo.cs:line 326
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp
(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m,
MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage
(Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc
(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr
hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
Line 192 refers to the executenonquery() method. I have
tested the query by itself in Access, and it inserts the
value just fine. Does anyone have any idea what could be
wrong? I have tracked it down to the loginID or Password
field, as the query works fine without those two in
there, but I am not sure what the problem is. Any help
would be much appreciated!
Kirk
OleDbConnection conn = new OleDbConnection(
@"Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\moneymakin.mdb");
String stmt = "INSERT INTO Person (FirstName,
LastName, Email, LoginID, Password) VALUES (" +
"'" + this.m_perFirstName + "', '" +
this.m_perLastName +
"', '" + this.m_emailAddress + "', '" +
this.m_loginID +
"', '" + this.m_password + "')";
MessageBox.Show(stmt);
//conn.Open();
OleDbCommand perCommand = new OleDbCommand
(stmt, conn);
perCommand.Connection.Open();
perCommand.ExecuteNonQuery();
//OleDbDataReader perReader =
perCommand.ExecuteNonQuery();
//perReader.Close();
I get the following error no matter what:
************** Exception Text **************
System.Data.OleDb.OleDbException: Syntax error in INSERT
INTO statement.
at
System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHand
ling(Int32 hr)
at
System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingle
Result(tagDBPARAMS dbParams, Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteCommandText
(Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteCommand
(CommandBehavior behavior, Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal
(CommandBehavior behavior, String method)
at System.Data.OleDb.OleDbCommand.ExecuteNonQuery()
at WindowsSample.Person.saveNewData() in c:\Documents
and Settings\Kirk Gray\My Documents\Borland Studio
Projects\WindowsSample\DataItems\Person.cs:line 192
at WindowsSample.PersonalInfo.btnPersonalSave_Click
(Object sender, EventArgs e) in c:\Documents and
Settings\Kirk Gray\My Documents\Borland Studio
Projects\WindowsSample\Forms\PersonalInfo.cs:line 326
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp
(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m,
MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage
(Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc
(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr
hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
Line 192 refers to the executenonquery() method. I have
tested the query by itself in Access, and it inserts the
value just fine. Does anyone have any idea what could be
wrong? I have tracked it down to the loginID or Password
field, as the query works fine without those two in
there, but I am not sure what the problem is. Any help
would be much appreciated!
Kirk