Inherits System.Web.UI.Page Dim connstr As String = "data source=SERVER;initial catalog=DB;user id=USER;password=PASSWORD;" Dim sqlStr As String = "SELECT * FROM Users" Dim dt As New DataTable
Private Sub btnLoad_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLoad.Click dt.Clear() Dim dataAdapter As New SqlClient.SqlDataAdapter(sqlStr, connstr) dataAdapter.Fill(dt) dataAdapter.Dispose() dgDisplay.DataSource = dt End Sub
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click Dim changes As Integer Dim dataAdapter As New SqlClient.SqlDataAdapter(sqlStr, connstr) Dim commandBuilder As New SqlClient.SqlCommandBuilder(dataAdapter) changes = dataAdapter.Update(dt) dataAdapter.Dispose() If changes > 0 Then MsgBox(changes & " changed rows were stored in the database.") Else MsgBox("no changes made.") End If End Sub
Msg#: 3399 posted 12:47 pm on May 15, 2006 (gmt 0)
Well one thing that you would have to do is add a textbox control or whatever you want to the datagrid. (I don't have vs.net 2003 installed on this computer, sorry) Then you would iterate through all the items of the datagrid on save click. Datagrid Iteration [xmlpitstop.com] has a good expample on how to do that.
I was looking at the code, and at the bottom when the example shows how to use the findcontrol method, I like to use DirectCast instead of the older CType, it is a bit faster, IMO.