Solved

Update db from datagrid

Posted on 2004-09-08
5
151 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
Comment Utility
0
 
LVL 22

Assisted Solution

by:mnasman
mnasman earned 50 total points
Comment Utility
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
Comment Utility
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
Comment Utility
I'd use the commandBuilder class since it's a single table.
0
 

Author Comment

by:Glen Gibb
Comment Utility
Thanks, all.

capt
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

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 …
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

772 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now