Solved

Updating Access Database from a datagrid

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

760 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now