G
graykagrayka
Hey all, hoping you can help with this odd problem...hopefully I am
just doing something really stupid. I have a small access database
with a bunch of text fields, and I want to insert a row, using 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();
conn.Close();
I get the following error msg when I run this update:
System.Data.OleDb.OleDbException: Syntax error in INSERT INTO
statement.
at
System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(Int32
hr)
at
System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(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)
I have no clue what the problem could be, but I know that when I only
use firstname, lastname, and emailaddress, the query works fine.
What could the problem be?
just doing something really stupid. I have a small access database
with a bunch of text fields, and I want to insert a row, using 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();
conn.Close();
I get the following error msg when I run this update:
System.Data.OleDb.OleDbException: Syntax error in INSERT INTO
statement.
at
System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(Int32
hr)
at
System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(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)
I have no clue what the problem could be, but I know that when I only
use firstname, lastname, and emailaddress, the query works fine.
What could the problem be?