Solved

ExecuteNonQuery() MS Access

Posted on 2010-08-30
7
329 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
Industry Leaders: 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!

 

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

Give Your Engineering Team a Productivity Boost

Learn why container technology is so powerful and how it can provide your team with productivity gains and other benefits.

Question has a verified solution.

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

This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

622 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