Connecting Tech Pros Worldwide Forums | Help | Site Map

simple ado question

kirk g
Guest
 
Posts: n/a
#1: Nov 22 '05
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.ExecuteCommandTextE rrorHand
ling(Int32 hr)
at
System.Data.OleDb.OleDbCommand.ExecuteCommandTextF orSingle
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.ExecuteReaderIntern al
(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


William Ryan
Guest
 
Posts: n/a
#2: Nov 22 '05

re: simple ado question


Password is a reserved word in Access and is the most likely culprit It
will run ok within access, but via ADO.NET, reserved words cause all kinds
of problems. The bandaid is to wrap it in bracekts [Password] but you or a
co-worker will invariably forget this sometime in the future. IMHO, get rid
of it b/c it's not worth the maintenance and headaches it will likely cause.

HTH,

Bill
"kirk g" <kyg@datatel.com> wrote in message
news:03c701c3d3f2$a38bcb60$a601280a@phx.gbl...[color=blue]
> 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.ExecuteCommandTextE rrorHand
> ling(Int32 hr)
> at
> System.Data.OleDb.OleDbCommand.ExecuteCommandTextF orSingle
> 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.ExecuteReaderIntern al
> (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
>[/color]


Kirk Gray
Guest
 
Posts: n/a
#3: Nov 22 '05

re: simple ado question


That was it...thank you very much for your help. I am
just getting started with .NET, C#, and ADO by doing some
stuff at home, and have been banging my head against a
wall on this one.
Much appreciated!
Kirk

[color=blue]
>-----Original Message-----
>Password is a reserved word in Access and is the most[/color]
likely culprit It[color=blue]
>will run ok within access, but via ADO.NET, reserved[/color]
words cause all kinds[color=blue]
>of problems. The bandaid is to wrap it in bracekts[/color]
[Password] but you or a[color=blue]
>co-worker will invariably forget this sometime in the[/color]
future. IMHO, get rid[color=blue]
>of it b/c it's not worth the maintenance and headaches[/color]
it will likely cause.[color=blue]
>
>HTH,
>
>Bill
>"kirk g" <kyg@datatel.com> wrote in message
>news:03c701c3d3f2$a38bcb60$a601280a@phx.gbl...[color=green]
>> 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[/color][/color]
(FirstName,[color=blue][color=green]
>> LastName, Email, LoginID, Password) VALUES (" +
>> "'" + this.m_perFirstName + "', '" +
>> this.m_perLastName +
>> "', '" + this.m_emailAddress[/color][/color]
+ "', '" +[color=blue][color=green]
>> 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[/color][/color]
INSERT[color=blue][color=green]
>> INTO statement.
>> at
>>[/color][/color]
System.Data.OleDb.OleDbCommand.ExecuteCommandTextE rrorHand[color=blue][color=green]
>> ling(Int32 hr)
>> at
>>[/color][/color]
System.Data.OleDb.OleDbCommand.ExecuteCommandTextF orSingle[color=blue][color=green]
>> Result(tagDBPARAMS dbParams, Object& executeResult)
>> at System.Data.OleDb.OleDbCommand.ExecuteCommandText
>> (Object& executeResult)
>> at System.Data.OleDb.OleDbCommand.ExecuteCommand
>> (CommandBehavior behavior, Object& executeResult)
>> at[/color][/color]
System.Data.OleDb.OleDbCommand.ExecuteReaderIntern al[color=blue][color=green]
>> (CommandBehavior behavior, String method)
>> at System.Data.OleDb.OleDbCommand.ExecuteNonQuery()
>> at WindowsSample.Person.saveNewData() in[/color][/color]
c:\Documents[color=blue][color=green]
>> 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&[/color][/color]
m,[color=blue][color=green]
>> MouseButtons button, Int32 clicks)
>> at System.Windows.Forms.Control.WndProc(Message& m)
>> at System.Windows.Forms.ButtonBase.WndProc(Message&[/color][/color]
m)[color=blue][color=green]
>> at System.Windows.Forms.Button.WndProc(Message& m)
>> at[/color][/color]
System.Windows.Forms.ControlNativeWindow.OnMessage[color=blue][color=green]
>> (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[/color][/color]
have[color=blue][color=green]
>> tested the query by itself in Access, and it inserts[/color][/color]
the[color=blue][color=green]
>> value just fine. Does anyone have any idea what could[/color][/color]
be[color=blue][color=green]
>> wrong? I have tracked it down to the loginID or[/color][/color]
Password[color=blue][color=green]
>> 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
>>[/color]
>
>
>.
>[/color]
William Ryan
Guest
 
Posts: n/a
#4: Nov 22 '05

re: simple ado question


My pleasure. Keep on trucking though, ADO.NET is a bit confusing at first,
but you'll quickly learn to love it.

Bill
"Kirk Gray" <kyg@datatel.com> wrote in message
news:040001c3d3f4$a72c86e0$a501280a@phx.gbl...[color=blue]
> That was it...thank you very much for your help. I am
> just getting started with .NET, C#, and ADO by doing some
> stuff at home, and have been banging my head against a
> wall on this one.
> Much appreciated!
> Kirk
>
>[color=green]
> >-----Original Message-----
> >Password is a reserved word in Access and is the most[/color]
> likely culprit It[color=green]
> >will run ok within access, but via ADO.NET, reserved[/color]
> words cause all kinds[color=green]
> >of problems. The bandaid is to wrap it in bracekts[/color]
> [Password] but you or a[color=green]
> >co-worker will invariably forget this sometime in the[/color]
> future. IMHO, get rid[color=green]
> >of it b/c it's not worth the maintenance and headaches[/color]
> it will likely cause.[color=green]
> >
> >HTH,
> >
> >Bill
> >"kirk g" <kyg@datatel.com> wrote in message
> >news:03c701c3d3f2$a38bcb60$a601280a@phx.gbl...[color=darkred]
> >> 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[/color][/color]
> (FirstName,[color=green][color=darkred]
> >> LastName, Email, LoginID, Password) VALUES (" +
> >> "'" + this.m_perFirstName + "', '" +
> >> this.m_perLastName +
> >> "', '" + this.m_emailAddress[/color][/color]
> + "', '" +[color=green][color=darkred]
> >> 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[/color][/color]
> INSERT[color=green][color=darkred]
> >> INTO statement.
> >> at
> >>[/color][/color]
> System.Data.OleDb.OleDbCommand.ExecuteCommandTextE rrorHand[color=green][color=darkred]
> >> ling(Int32 hr)
> >> at
> >>[/color][/color]
> System.Data.OleDb.OleDbCommand.ExecuteCommandTextF orSingle[color=green][color=darkred]
> >> Result(tagDBPARAMS dbParams, Object& executeResult)
> >> at System.Data.OleDb.OleDbCommand.ExecuteCommandText
> >> (Object& executeResult)
> >> at System.Data.OleDb.OleDbCommand.ExecuteCommand
> >> (CommandBehavior behavior, Object& executeResult)
> >> at[/color][/color]
> System.Data.OleDb.OleDbCommand.ExecuteReaderIntern al[color=green][color=darkred]
> >> (CommandBehavior behavior, String method)
> >> at System.Data.OleDb.OleDbCommand.ExecuteNonQuery()
> >> at WindowsSample.Person.saveNewData() in[/color][/color]
> c:\Documents[color=green][color=darkred]
> >> 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&[/color][/color]
> m,[color=green][color=darkred]
> >> MouseButtons button, Int32 clicks)
> >> at System.Windows.Forms.Control.WndProc(Message& m)
> >> at System.Windows.Forms.ButtonBase.WndProc(Message&[/color][/color]
> m)[color=green][color=darkred]
> >> at System.Windows.Forms.Button.WndProc(Message& m)
> >> at[/color][/color]
> System.Windows.Forms.ControlNativeWindow.OnMessage[color=green][color=darkred]
> >> (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[/color][/color]
> have[color=green][color=darkred]
> >> tested the query by itself in Access, and it inserts[/color][/color]
> the[color=green][color=darkred]
> >> value just fine. Does anyone have any idea what could[/color][/color]
> be[color=green][color=darkred]
> >> wrong? I have tracked it down to the loginID or[/color][/color]
> Password[color=green][color=darkred]
> >> 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
> >>[/color]
> >
> >
> >.
> >[/color][/color]


Closed Thread


Similar .NET Framework bytes