Solved

Error is occuer when inserting to access table

Posted on 2004-08-02
6
258 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 50 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

809 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