Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Error is occuer when inserting to access table

Posted on 2004-08-02
6
Medium Priority
?
285 Views
Last Modified: 2010-08-05
Check this code there's a error


cnDB.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
                    "Data Source=D:\DotNet\CityBank\db.mdb;"
Dim daInsert As OleDb.OleDbDataAdapter

cnDB.Open()

                Dim cmInsertB As New OleDbCommand()
                cmInsertB.CommandText = "Insert into BatchHeader(BatchNo,BatchDate) Values ('11112222','19/07/2004')"
                cmInsertB.ExecuteNonQuery()
0
Comment
Question by:kaudaboy
  • 2
6 Comments
 
LVL 1

Accepted Solution

by:
FRIBBLE1 earned 200 total points
ID: 11703398
Hi

The first problem i can see in your code is your not giveing your OleDbcommand a conection you need this line of code.

cmInsertB.connection = cnDB

that will tell your OleDbcommand where it conecting to.

if your just running and INSERT sql command you don't need the OleDbDataAdapter.

i think this should be the code you need to use.

Dim cnDB as new OleDbConnection
Dim cmInsertB  as new OleDbCommand

cnDB = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\DotNet\CityBank\db.mdb;"

cmInsertB.conection = cnDB

cmInsertB.CommandText = "Insert into BatchHeader(BatchNo,BatchDate) Values ('11112222','19/07/2004')"


cnDB.open
cmInsertB.ExecuteNonQuery()
cnDB.close

give that try. My speeling might be slightly off so right it your self useing the intle senes.






0
 
LVL 1

Expert Comment

by:snayaks
ID: 11703702
Hi

I think the error is in "INSERT" command. If BatchDate is  Date Type then, User Convert(DateTime,,) or Datevalue or any Date Conversion function.

snayaks
0
 
LVL 1

Expert Comment

by:FRIBBLE1
ID: 11703836
Ok try rungin the insert satement with this comand


cmInsertB.CommandText = "Insert into BatchHeader(BatchNo,BatchDate) Values ('11112222','"  & system.datetime & "')"

see if that inserts. if it dosent try copying the error messeg and past it.

0
 

Author Comment

by:kaudaboy
ID: 11711995
I have manage to do that.. thanks 4 u're help


Dim myConnection As OleDbConnection
                Dim myOleCommand As OleDbCommand

                myConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\DotNet\CityBank\db.mdb")
                myOleCommand = New OleDbCommand("Insert into BatchHeader(BatchNo,BatchDate) Values ('11112222','19/07/2004')", myConnection)

                Try
                    myConnection.Open()
                    myOleCommand.ExecuteNonQuery()
                    MsgBox("New Record inserted into Customers table in northwind.")
                Catch myException As Exception
                    MsgBox("Couldn't insert record: " + myException.ToString())
                Finally
                    myConnection.Close()
                End Try
0

Featured Post

Independent Software Vendors: 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

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Screencast - Getting to Know the Pipeline

885 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