|
-
Sep 20th, 2006, 08:36 PM
#1
Thread Starter
Member
help! insert into mdb database using datatable
hi,
i'm having a problem with this set of codes.
i'm trying to insert data into datatable and update it into a database but everytime i click the save button
an OledbException will occur
VB Code:
Private myConnect As OleDbConnection
Private myDataadapter As OleDbDataAdapter
Private myDataTable As DataTable
Private cmbInsert As OleDbCommand
Private Sub FormItemType_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim dbConnect As String = "Provider=Microsoft.JET.OLEDB.4.0;data source=D:\prodType.mdb"
myConnect = New OleDbConnection(dbConnect)
Dim mySqlQuery As String = "Select *from ProductTypeInfo"
myDataTable = New DataTable
myDataadapter = New OleDbDataAdapter(mySqlQuery, dbConnect)
cmbInsert = New OleDbCommand
cmbInsert.CommandText = "Insert into ProductTypeInfo (ProductTypeID, ProductTypeName) values (@ProductTypeID, @ProductTypeName)"
cmbInsert.Connection = myConnect
cmbInsert.Parameters.Add(New OleDbParameter("@ProductTypeID", OleDbType.BSTR))
cmbInsert.Parameters.Add(New OleDbParameter("@ProductTypeName", OleDbType.BSTR))
myDataadapter.InsertCommand = cmbInsert
myConnect.Open()
myDataadapter.Fill(myDataTable)
myConnect.Close()
DataGrid1.DataSource = myDataTable
End Sub
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
myConnect.Open()
myDataadapter.Update(myDataTable)
myConnect.Close()
End Sub
-
Sep 20th, 2006, 09:03 PM
#2
Re: help! insert into mdb database using datatable
You should always provide the error message when posting code that throws an exception, otherwise we're guessing to a degree. I'm guessing the issue is the types you've chosen for your parameters. What sort of data do your columns contain? BSTR is an odd choice for most data. If your columns contain text then you should probably be using VarChar as the type. If ProductTypeID contains numbers then the type for that parameter should be Integer.
-
Sep 21st, 2006, 03:57 AM
#3
Thread Starter
Member
Re: help! insert into mdb database using datatable
-
Sep 21st, 2006, 04:28 AM
#4
Re: help! insert into mdb database using datatable
So... does that mean that the problem is solved? If so you then you should mark your thread as resolved from the Thread Tools menu. If not then feedback's a good idea, like "I'll try that and get back to you". Otherwise people might just unsubscribe from your thread and thus be less likely to help you if you add another post.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|