Solved

ExecuteNonQuery() MS Access

Posted on 2010-08-30
7
309 Views
Last Modified: 2013-11-27

VS 2005 / VB.Net
Simple Insert Query.

Using Execute Non Query -


I am not able to insert a simple query.

Table has only two columns ( StatesId which is AutoNumber and StateShortName which is Text DataType ).

Dim myOleCommand As OleDbCommand

Dim myConn As New OleDbConnection("C:\Enrollment Form\EnrollmentApp\EnrollmentApp\EnrollmentDB.mdb")



myConn.Open()

Dim strCommand As String

strCommand = "Insert into tmpStates (StateShortName) values('Chokka')"

myOleCommand = New OleDbCommand(strCommand, myConn)

myOleCommand.ExecuteNonQuery()

myConn.Close()

Open in new window

0
Comment
Question by:chokka
  • 4
  • 3
7 Comments
 
LVL 53

Expert Comment

by:Dhaest
ID: 33558706
Do you get any errors ?

try
   myConn.Open()
   Dim strCommand As String
   strCommand = "Insert into tmpStates (StateShortName) values('Chokka')"
   myOleCommand = New OleDbCommand(strCommand, myConn)
   myOleCommand.ExecuteNonQuery()
   myConn.Close()
catch ex as Exception

end try
0
 

Author Comment

by:chokka
ID: 33558720
No, I am not getting any errors
0
 

Author Comment

by:chokka
ID: 33558728
I am not getting any errors and Insertion is not happeing ..
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Author Comment

by:chokka
ID: 33558753
Once i closed the app and opened again, i am getting errors as follows

{"Format of the initialization string does not conform to specification starting at index 0."}
{"Format of the initialization string does not conform to specification starting at index 0."}

Open in new window

0
 
LVL 53

Accepted Solution

by:
Dhaest earned 500 total points
ID: 33558882
Try the following (I think that there is something wrong with your connectionstring. I think you should get an error on that !

Dim myOleCommand As OleDbCommand
Dim myConn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Enrollment Form\EnrollmentApp\EnrollmentApp\EnrollmentDB.mdb;User Id=admin;Password=;)
try
   myConn.Open()
   Dim strCommand As String
   strCommand = "Insert into tmpStates (StateShortName) values('Chokka')"
   myOleCommand = New OleDbCommand(strCommand, myConn)
   myOleCommand.ExecuteNonQuery()
   myConn.Close()
catch ex as Exception

end try
0
 

Author Comment

by:chokka
ID: 33559055
Thanks Dhaest:

It works ..!

Now, i need to move this connection string to App.Config file ..!

0
 
LVL 53

Expert Comment

by:Dhaest
ID: 33560808
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

930 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now