Solved

Updating Access Database from a datagrid

Posted on 2007-04-09
2
272 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: 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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
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…

751 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