Solved

Update db from datagrid

Posted on 2004-09-08
5
155 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 200 total points
ID: 12012564
0
 
LVL 22

Assisted Solution

by:Mohammed Nasman
Mohammed Nasman earned 50 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 200 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 50 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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Help with sorting data in Listbox using VB.NET 3 62
Creating a route in asp.net webforms 2 27
VB.Net Report Printing Issue 3 35
vb.net class 3 16
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…
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…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

810 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