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

x
?
Solved

Write data back to access table from DataGrid control

Posted on 2006-06-22
3
Medium Priority
?
246 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 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
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…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

688 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