Solved

Error is occuer when inserting to access table

Posted on 2004-08-02
6
273 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: 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

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

628 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