I have a datagrid that I use to display data from a SQL 2000 table. I am trying to write back any changes the user makes to the datagrid data back to the original table but don't know the proper method to do this.
Can anyone help?
Here is the code that populates the datagrid:
HERE’S MY CODE:
Dim TheDatabase As System.Data.SqlClient.SqlConnection
Dim ConnectionString As String
Dim cmd3 As New SqlCommand
Dim Adp3 As New SqlDataAdapter
ConnectionString = "Data Source=;Initial Catalog=Adjustments;User ID=;Password="
TheDatabase = New SqlClient.SqlConnection(ConnectionString)
cmd3.Connection = TheDatabase
cmd3.CommandText = "spGetMeasurementDetail"
cmd3.CommandType = CommandType.StoredProcedure
cmd3.Parameters.AddWithValue("@AdjustmentId", gGUID)
Adp3 = New SqlDataAdapter(cmd3)
adp3.Fill(dt3)
DataGridView1.AutoGenerateColumns = True
DataGridView1.DataSource = dt3
With Me.DataGridView1
.SelectionMode = DataGridViewSelectionMode.FullRowSelect
.MultiSelect = False
.Columns(0).Visible = False
.Columns(1).Visible = False
.Columns(2).Visible = False
.Columns(3).Visible = False
.Columns(4).Visible = False
.Columns(5).Width = 85
.Columns(6).Width = 75
.Columns(7).Visible = False
End With
Here’s the Stored Procedure
PROCEDURE spGetMeasurementDetail(@AdjustmentId uniqueidentifier)
BEGIN
SELECT i.id as InitId, I.id as DispId, I.AdjustmentHeaderId, I.AdjustmentDetailId, I.MeasurementId, I.USOC as USOC, I.ROW as InitDetID, D.ROW as DispDetID
FROM tAdjustmentEx as I
LEFT OUTER JOIN tAdjustmentEx as D ON
I.AdjustmentHeaderId = D.AdjustmentHeaderId AND I.MeasurementId = D.MeasurementId AND
D.TypeCode='D'
WHERE I.AdjustmentHeaderID=@AdjustmentId and I.TypeCode = 'I'
ORDER BY I.Row
END
Here’s what will show up in the datagrid.
USOC InitDetID
9086 2
I could use some suggestions on how to code the write back command that will allow the user to change the data in the datagrid and have those changes be written back to my tAdjustment table.
Thanks in advance for any help or suggestions,
Greg