Solved

Error is occuer when inserting to access table

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Multiple file Upload asp.net 2 40
Get String split 5 48
Recommendation vb6 to vb.net or others 14 112
Make all values in arrayist to titlecase+vb.net 23 27
This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

895 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now