Solved

Updating Access Database from a datagrid

Posted on 2007-04-09
2
269 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

679 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