Solved

Error is occuer when inserting to access table

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

707 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

18 Experts available now in Live!

Get 1:1 Help Now