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




Reply With Quote