Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Write data back to access table from DataGrid control

Posted on 2006-06-22
3
Medium Priority
?
249 Views
Last Modified: 2010-04-23
I have a form with a Data Grid control bound to a table and am trying to write back changes to a table.  I would like the user to click on a button to save the changes. How do I do this.  Here is my code, to fill the grid.

  Dim dbConnection As New OleDbConnection
       Dim da As New OleDbDataAdapter
        Dim dbCommand As New OleDbCommand
        Dim dt As New DataTable
        Dim ds As New DataSet
        Dim dr As DataRow
        Dim i As Integer
        Dim s As String


        dbConnection.ConnectionString = "Provider = Microsoft.Jet.OLEDB.4.0;Data Source=d:\data\docs\metalogic\test.mdb"


        Try
            dbConnection.Open()

        Catch ex As Exception
            MsgBox("Cannot open Database" & vbCr & ex.Message, MsgBoxStyle.Critical, "Error!")
            Exit Sub
        End Try
        Dim SQLStr As String
        Dim strRate As String


        SQLStr = "select *  from " & tablename



        dbCommand.Connection = dbConnection
        dbCommand.CommandType = CommandType.Text

        dbCommand.CommandText = SQLStr
        da.SelectCommand = dbCommand
        Dim cb As New OleDbCommandBuilder(da)

        da.Fill(dt)
        '===========================================

        '

        grdTable.DataSource = dt


==============================

Thanks,
B Sturge





0
Comment
Question by:bsturge
3 Comments
 
LVL 41

Assisted Solution

by:graye
graye earned 664 total points
ID: 16959342
You'd use the DataAdapter's Update method to perfrom this task...

Take a look at the following articles on how to write VB.Net code to save changes back to the underlying database  http://home.hot.rr.com/graye/Articles/SavingDataADO.htm

0
 
LVL 6

Assisted Solution

by:Nandakumar Sakthivel
Nandakumar Sakthivel earned 668 total points
ID: 16959406
Hi,
Instead of creating the data Adapter manually.you can configure the Data Adapter using the tool in visual studio.
In the Data tab of tool  there are different types of adapters available for different databases.It will generate the
 query automatically when you drag and drop and configure it
you need to use

       DataAdapter.Update(DataSet) command for updating the table

 for more info abt using adapters
    http://www.vb-helper.com/howto_net_bound_datagrid.html
    http://www.developerfusion.co.uk/show/4278/4/


Thanks,
Nanda
 
0
 
LVL 2

Accepted Solution

by:
Bill_PSC earned 668 total points
ID: 16961936
Greetings.

First you need to fill the dataset.

da.Fill(ds,"dt")

then on the button click event.

   Me.BindingContext(DS, "DT").EndCurrentEdit()
                DA.Update(DS, "DT")
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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…
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…
Integration Management Part 2

971 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