Solved

ExecuteNonQuery() MS Access

Posted on 2010-08-30
7
323 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
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 …
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…

710 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