DataGrid update
Messages   Related Types
This message was discovered on ASPFriends.com 'winforms-cs' list.


Thomas Breivik
How does one update a database after a program user has updated some
information in a datagrid? The datagrid has been bound to a dataset. Do I
have to update the dataset from the datagrid, then save the dataset to the
database?

-Thomas

Reply to this message...
 
    
Scott Berry
The grid doesn't keep its own copy of the data: when you change values
in the grid, the underlying DataSet's values change, too. (So, you're
pretty much right, but you can skip the update the dataset step and just
call update on your dataadapter with your dataset.)
    -Scott

    This posting is provided "AS IS" with no warranties, and confers
no rights.

-----Original Message-----
From: Thomas Breivik [mailto:Click here to reveal e-mail address]=20
Sent: Thursday, April 25, 2002 6:24 AM
To: winforms-cs
Subject: [winforms-cs] DataGrid update

How does one update a database after a program user has updated some
information in a datagrid? The datagrid has been bound to a dataset. Do
I
have to update the dataset from the datagrid, then save the dataset to
the
database?

-Thomas

| [winforms-cs] member Click here to reveal e-mail address =3D YOUR ID
| http://www.asplists.com/asplists/winforms-cs.asp =3D JOIN/QUIT

Reply to this message...
 
    
Gress
I am trying to do basically this same thing, but have no idea how to preform the update. (its my first time using datagrids / sets etc)

Ive posted most of my code below. This takes care of loading the data set when querydatabase is called. I want to put a button called update that would send the new info to the db, but how do I do this?

Option Explicit On
Imports System.Data.SqlClient

Public Class Form1
Inherits System.Windows.Forms.Form
Public ds As New DataSet
Public myCmd As SqlCommand
Public myReader As SqlDataReader

#Region " Windows Form Designer generated code "

Dim CallDataBindToDataGrid As New MethodInvoker(AddressOf Me.DataBindToDataGrid)
Dim MyDataSet As DataSet
Dim MyDataAdapter As SqlDataAdapter
Dim MyConnection As New SqlConnection("Initial Catalog=Gress; Data Source=DB;Integrated Security=SSPI;")

'* This sub is straight out of the code I found. It was supposed to work on a differnt
' * DB, so i dont know if the dataMember bit needs to be changed..
Public Sub DataBindToDataGrid()
DataGrid1.DataSource = MyDataSet
DataGrid1.DataMember = "authors"
MyDataAdapter = Nothing
MyDataSet = Nothing
End Sub

Public Sub QueryDataBase(ByVal i As Integer)
Dim MyQueryString As String = "SELECT * FROM tbl_JobPhase where jobid = " & i
MyDataSet = New DataSet
MyConnection.Open()
Dim cmd As New SqlCommand(MyQueryString, MyConnection)
MyDataAdapter = New SqlDataAdapter(cmd)
MyDataAdapter.Fill(MyDataSet, "authors")
MyConnection.Close()
Me.BeginInvoke(CallDataBindToDataGrid)
End Sub

End Class

--------------------------------
From: Gress
Reply to this message...
 
 
System.Data.DataSet
System.Data.SqlClient.SqlCommand
System.Data.SqlClient.SqlConnection
System.Data.SqlClient.SqlDataAdapter
System.Data.SqlClient.SqlDataReader
System.Web.UI.WebControls.DataGrid
System.Windows.Forms.DataGrid
System.Windows.Forms.Form
System.Windows.Forms.MethodInvoker




Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
 
 Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us - Terms of Use - Privacy Policy - www.dotnet247.com