Groups | Blog | Home
all groups > dotnet ado.net > may 2007 >

dotnet ado.net : 'INSERT INTO' in Access


EmilH
5/7/2007 12:00:00 AM
Hi.

I wrote the code to insert a new record into an Access database. I get no
errors. However a new record is not inserted.
Any ideas?

Please help.
Thanks.Emil.

Patrice
5/7/2007 12:00:00 AM
On Error resume next ? No dbFailOnError option ? What if the query is
executed as an action query ? Does the Access UI show then an error ?

"EmilH" <emilslx@yahoo.com> a écrit dans le message de news:
ufnFC$HkHHA.3472@TK2MSFTNGP04.phx.gbl...
[quoted text, click to view]

Patrice
5/7/2007 12:00:00 AM
Sorry I'm not sure what I thought this question was in an Access group ;-)

You may want also to check that the SELECT part of your statement does
return records (note for example that the wildcard character is % instead of
*).

Showing us some code could perhaps helps...


"EmilH" <emilslx@yahoo.com> a écrit dans le message de news:
ufnFC$HkHHA.3472@TK2MSFTNGP04.phx.gbl...
[quoted text, click to view]

EmilH
5/7/2007 12:00:00 AM
forgot to mention that command is sent from my c# application.
Emil.

[quoted text, click to view]

Miha Markic
5/7/2007 12:00:00 AM
What does code look like?

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

[quoted text, click to view]
EmilH
5/7/2007 12:00:00 AM
here is the code:

command.CommandText = "INSERT Category (Name, Interval, Quantity) VALUES(\""
+ categoryTB.Text +

"\",\"" + interimCB.SelectedItem.ToString() + "\",\"" + quantityTB.Text +
"\")";

oledb.Open();

command.ExecuteNonQuery();

oledb.Close();



Emil.


[quoted text, click to view]

Patrice
5/7/2007 12:00:00 AM
Also a common cause is if the db file is copied as part of the project
output directory. That is the db file that is in your project is left
unchanged, you just update a copy...

"EmilH" <emilslx@yahoo.com> a écrit dans le message de news:
efeDxhIkHHA.4032@TK2MSFTNGP02.phx.gbl...
[quoted text, click to view]

Paul Clement
5/7/2007 9:36:30 AM
[quoted text, click to view]

¤ here is the code:
¤
¤ command.CommandText = "INSERT Category (Name, Interval, Quantity) VALUES(\""
¤ + categoryTB.Text +
¤
¤ "\",\"" + interimCB.SelectedItem.ToString() + "\",\"" + quantityTB.Text +
¤ "\")";
¤
¤ oledb.Open();
¤
¤ command.ExecuteNonQuery();
¤
¤ oledb.Close();
¤

Name is a reserved word and must be enclosed within brackets.


Paul
~~~~
Paul Clement
5/7/2007 12:01:33 PM
[quoted text, click to view]

¤ > ¤ here is the code:
¤ > ¤
¤ > ¤ command.CommandText = "INSERT Category (Name, Interval, Quantity)
¤ > VALUES(\""
¤ > ¤ + categoryTB.Text +
¤ > ¤
¤ > ¤ "\",\"" + interimCB.SelectedItem.ToString() + "\",\"" + quantityTB.Text
¤ > +
¤ > ¤ "\")";
¤ > ¤
¤ > ¤ oledb.Open();
¤ > ¤
¤ > ¤ command.ExecuteNonQuery();
¤ > ¤
¤ > ¤ oledb.Close();
¤ > ¤
¤ >
¤ > Name is a reserved word and must be enclosed within brackets.
¤
¤ This sql statement is starting to be like a picture where you have to find
¤ all the differences :-)

Something tells me he's bypassing the exceptions as well. ;-)


Paul
~~~~
Miha Markic
5/7/2007 1:27:31 PM
Hi Emil,

Shouldn't it be INSERT *INTO* Category?

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/
[quoted text, click to view]
Patrice
5/7/2007 2:45:11 PM
To add to Miha advice, I would also double check the code to see if it
doesn't currently hide some exceptions. IMO it shouldn't fail silently...

"Miha Markic" <miha at rthand com> a écrit dans le message de news:
eEAfYrJkHHA.3120@TK2MSFTNGP05.phx.gbl...
[quoted text, click to view]

EmilH
5/7/2007 4:29:05 PM
Good point, but it didn't help. Thanks anyway!
Emil.


[quoted text, click to view]

Miha Markic
5/7/2007 6:49:38 PM

[quoted text, click to view]

This sql statement is starting to be like a picture where you have to find
all the differences :-)

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/
AddThis Social Bookmark Button