[HELP] Editing MS ACCESS directly from DataGridView in VB

Started on the old forum in October 2012 · view the original in the archive · old links redirect here

1 reply · 360 views · started 14 years ago · 1 min read

2 participants
Jervy Senior · 250 posts #1

I'm using ms access 2003 and visual basic 2005. In my DELETE button I manage to delete a row in ms access direct from datagridview using this code

 Dim con As New OleDbConnection
    Dim dt As New DataTable
    Dim ds As New DataSet
    Dim da As New OleDbDataAdapter
     
    Private Sub Informations_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
       
        Me.MembersTableAdapter.Fill(Me.DataSet4.members)
con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & System.Environment.CurrentDirectory & "\LibraryDatabase.mdb"

        ds.Tables.Add(dt)
        da = New OleDbDataAdapter("Select * from members", con)
        da.Fill(dt)

        DataGridView2.DataSource = dt.DefaultView
        con.Close()

   Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        Dim dt As New DataTable
        Dim ds As New DataSet
        ds.Tables.Add(dt)
        Dim da As New OleDbDataAdapter
        Dim i As Integer
        i = DataGridView2.CurrentRow.Index

        con.Open()

        da = New OleDbDataAdapter("Select * from members", con)
        da.Fill(dt)

        dt.Rows(i).BeginEdit()
        dt.Rows(i).Delete()
        dt.Rows(i).EndEdit()

        Dim cb As New OleDbCommandBuilder(da)
        da.Update(dt)

        DataGridView2.DataSource = dt.DefaultView

        con.Close()

    End Sub

Now my problem is how to convert this code to modify a cell in datagridview and update the ms access as well. I tried a lot of codes in the internet but none of them works. Any vb guru here? Help me please. Thanx in advance.

ACIDCORE Junior · 30 posts #2

u r using adodb...i think it is much easier to use adodc...

Write your reply now; next you create a free account (or sign in) and it is posted right away. Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close