Solved

Updating Access Database from a datagrid

Posted on 2007-04-09
2
268 Views
Last Modified: 2010-04-24
I need to insert into an access database the values in datagrid1.  How can I do this?  Thank you


  Dim sConn As String = "Driver={Microsoft Access Driver (*.mdb)};Dbq=c:\Splash\Splash.mdb;Uid=Admin;Pwd=;"  '<<< note the change here
        Dim cn As New OdbcConnection(sConn)

        Try
            cn.Open()

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try


        Dim sSQL As String = "select * from tblmember where lngmemberid =" & -999
        Dim da As New OdbcDataAdapter(sSQL, cn)
        Dim ds As New DataSet

        Try
            Dim count
            da.Fill(ds)
            DataGrid1.DataSource = ds.Tables(0)
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try


        'frmloading.Hide()
        Dim tablestyle As New DataGridTableStyle
        tablestyle.MappingName = ds.Tables(0).TableName




        Dim column5 As New DataGridTextBoxColumn
        column5.MappingName = "strfname"
        column5.Width = 80
        column5.HeaderText = "First Name"
        tablestyle.GridColumnStyles.Add(column5)

        column5 = New DataGridTextBoxColumn
        column5.MappingName = "strlname"
        column5.Width = 200
        column5.HeaderText = "Last Name"
        tablestyle.GridColumnStyles.Add(column5)


        column5 = New DataGridTextBoxColumn
        column5.MappingName = "dtmdob"
        column5.Width = 120
        column5.HeaderText = "Date"
        tablestyle.GridColumnStyles.Add(column5)
        Me.DataGrid1.TableStyles.Add(tablestyle)
0
Comment
Question by:running32
  • 2
2 Comments
 
LVL 18

Expert Comment

by:Priest04
ID: 18879454
If you want to update changed data from grid (more precise from datatable, since grid is bound to datatable), it is done with DataAdapter's Fill method. But first you need to create Insert, Update and Delete queries for DataAdapter that you have used to fill datatable. This can be done either in design mode using wizard to generate this objects for you, or you retype them manually (hardest way), or you can use CommandBuilder object and pass DataAdapter to its sonctructor, and CommandBuilder will generate UpdateCommand, InsertCommand and DeleteCOmmand objects for you. Then all you need to do is call DataAdapter's Fill method

Goran
0
 
LVL 18

Accepted Solution

by:
Priest04 earned 500 total points
ID: 18882106
Pardon, I created a mistake buy saying update is done with Fill method, but it is odne with the DataDapters Update method. Sorry for the typing mistake.

Goran
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question