Solved

Update db from datagrid

Posted on 2004-09-08
5
158 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
[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
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

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

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

735 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