Solved

Write data back to access table from DataGrid control

Posted on 2006-06-22
3
228 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
[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
3 Comments
 
LVL 41

Assisted Solution

by:graye
graye earned 166 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 167 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 167 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

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

Title # Comments Views Activity
VB.Net WebRequest Code from JSON curl 7 94
SSRS 2016 Rendering HTML tables 3 62
Get sourcecode path 14 47
Copying from a network share 3 26
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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

726 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