Solved

ExecuteNonQuery() MS Access

Posted on 2010-08-30
7
306 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
Comment Utility
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
Comment Utility
No, I am not getting any errors
0
 

Author Comment

by:chokka
Comment Utility
I am not getting any errors and Insertion is not happeing ..
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:chokka
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks Dhaest:

It works ..!

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

0
 
LVL 53

Expert Comment

by:Dhaest
Comment Utility
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

743 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

17 Experts available now in Live!

Get 1:1 Help Now