Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Updating Access Database from a datagrid

Posted on 2007-04-09
2
Medium Priority
?
284 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 2000 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

Technology Partners: 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

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses

721 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