'INSERT INTO' in Access

  • Thread starter Thread starter EmilH
  • Start date Start date
E

EmilH

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.
 
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 ?
 
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...
 
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.


Miha Markic said:
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/

EmilH said:
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.
 
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...
 
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/
EmilH said:
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.


Miha Markic said:
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/

EmilH said:
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.
 
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 said:
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/
EmilH said:
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.


Miha Markic said:
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/

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.
 
¤ 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
~~~~
Microsoft MVP (Visual Basic)
 
Paul Clement said:
¤ 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 :-)
 
On Mon, 7 May 2007 18:49:38 +0200, "Miha Markic" <miha at rthand com> wrote:

¤ > ¤ 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
~~~~
Microsoft MVP (Visual Basic)
 
Back
Top