[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Update db from datagrid

Posted on 2004-09-08
5
Medium Priority
?
164 Views
Last Modified: 2010-05-18
My datagrid's datasource is a db table.

If the user edits a cell, how do I update the db with the change?  

I need to know what value has changed and make an update to SQL Server.

A code snippet, svp.

capt
0
Comment
Question by:Glen Gibb
5 Comments
 
LVL 18

Accepted Solution

by:
DotNetLover_Baan earned 800 total points
ID: 12012564
0
 
LVL 22

Assisted Solution

by:Mohammed Nasman
Mohammed Nasman earned 200 total points
ID: 12013698
Hello

  Use SqlDataAdapter to fill Dataset, and then bind the DataGrid to the Dataset
when you would like the changes that happen to the Datagrid to be updated to sql server, use SqlDataAdapter.Update for that

it's easy and doesn't require from you much code ;-)
0
 
LVL 27

Assisted Solution

by:planocz
planocz earned 800 total points
ID: 12015490
Sample code.............

    Public DS As DataSet
    Public CurRow As DataRow
    Public sTableName As String = "MyTable"
    Public myDataAdapter As OleDb.OleDbDataAdapter
    Dim icnt As Short = 0

        For Each CurRow In DS.Tables(sTableName).Rows
            CurRow.BeginEdit()
            CurRow("OnHand") = datagrid.Item(icnt, 1)         '<---- Column 1
            CurRow("Name") = datagrid.Item(icnt, 2)            '<---- Column 2
            CurRow.EndEdit()
            icnt +=1
        Next
        myDataAdapter.Update(DS.Tables(sTableName))
        MsgBox("Records edited successfully")
0
 
LVL 5

Assisted Solution

by:thenrich
thenrich earned 200 total points
ID: 12015540
I'd use the commandBuilder class since it's a single table.
0
 

Author Comment

by:Glen Gibb
ID: 12031327
Thanks, all.

capt
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Integration Management Part 2
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

834 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