Solved

ExecuteNonQuery() MS Access

Posted on 2010-08-30
7
316 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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
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…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
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…

821 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