how do you update an access db?

  • Thread starter Thread starter Paul#
  • Start date Start date
P

Paul#

I am trying to update an access database.

I have been able to perform the following:
1) open db
2) create dataset from db
3) modify dataset

my troubles lie in:
4) updating the access database with the new dataset
It gives me an exception from system.data.oledbexception.

'my function call is:
'***********************************************************************

CreateCmdsAndUpdate("Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Password=""""; User ID=Admin;" & _
"Data Source=" & strpathname, "SELECT AXHTP FROM Cst_all",
"Table", _
"UPDATE Cst_all")

'my function is:
'************************************************************************

Public Function CreateCmdsAndUpdate(ByVal myConnection As String,
ByVal mySelectQuery As String, ByVal myTableName As String, ByVal
myUpdateQuery As String) As DataSet
Dim myConn As New OleDbConnection(myConnection)
Dim myDataAdapter As New OleDbDataAdapter
Dim oCommandbuilder As New SqlClient.SqlCommandBuilder


myDataAdapter.SelectCommand = New OleDbCommand(mySelectQuery,
myConn)
myDataAdapter.UpdateCommand = New OleDbCommand(myUpdateQuery,
myConn)


myConn.Open()

Dim custDS As DataSet = New DataSet
Dim currentrow As DataRow

myDataAdapter.Fill(custDS)

For Each currentrow In custDS.Tables(myTableName).Rows

currentrow.Item(0) =
currentrow.Item(0).ToString.Replace("A", " ")

Next

DataGrid.DataSource = custDS

myDataAdapter.Update(custDS, myTableName) 'error occurs here

myConn.Close()

Return custDS

End Function
'*************************************************************************

Thanks for your help,
Paul#
 
Paul,

What exception, however when item(0) is your primary key, than the
updatecommand will not be sufficient because you will need the insert
because it is an insert.

Cor
 
Back
Top