user225269
user225269

Reputation: 10913

duplicate in updating ms access database

Here is the error: http://screencast.com/t/ZDVhNmJiOTgt

Please help, here is my code: what can I do to solve this error

       Try
        If MessageBox.Show("Save and update database?", _
        "Confirmation", MessageBoxButtons.YesNo) = _
        Windows.Forms.DialogResult.Yes Then
            Dim idXs As Integer
            Dim dSet As New DataSet
            Dim conn As New OleDb.OleDbConnection
            Dim strSQL As String

            conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\ACCESS DATABASE\search.mdb"
            conn.Open()

            strSQL = "Select * From GH"
            Dim da As OleDbDataAdapter
            da = New OleDb.OleDbDataAdapter(strSQL, conn)
            da.Fill(dSet, "GH") 'fill dataset

            'code for editing records
            Dim cb As New OleDbCommandBuilder(da)
            idXs = Form1.idX 'retrieve index from Form1
            dSet.Tables("GH").Rows(idXs).Item(0) = TextBox1.Text
            dSet.Tables("GH").Rows(idXs).Item(1) = TextBox2.Text
            dSet.Tables("GH").Rows(idXs).Item(2) = TextBox3.Text
            dSet.Tables("GH").Rows(idXs).Item(3) = TextBox4.Text
            da.Update(dSet, "GH") 'update database

            conn.Close() 'close connection
            reloadMyMain() 'show new changes in form1 if any
        Else
            DSET.RejectChanges() 'cancel delete
        End If
    Catch ex As Exception
        MsgBox(ex.ToString) 'show exception message
    End Try

Upvotes: 1

Views: 1028

Answers (3)

Roland Bouman
Roland Bouman

Reputation: 31981

The error message that you point to reads:

'F:\ACCESS DATABASE\search.mdb' is not a valid path.

Apparently you mistyped the path to the db in the conn.ConnectString = ... line.

Upvotes: 0

Quassnoi
Quassnoi

Reputation: 425623

It seems you just don't have the file F:\ACCESS DATABASE\search.mdb.

Check the path to your access database file.

Upvotes: 0

Dani
Dani

Reputation: 15069

you need to check the table in the DB - one of the columns is either indexed and can only contain unique values, or has some other limitation.

you enter a data into that column that it can not hold.

Try to "UPDATE" the Data Manually directly on the table and you will see what is wrong...

Upvotes: 2

Related Questions