472,126 Members | 1,548 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,126 software developers and data experts.

DataSet insert problem

I've a dataGrid set up (the standard msdn example) with a
SqlDataAdapter, and DataSet.

The problem is that after inserting a new row using the
LinkButton1_Click() (code below)
then edit the values
I then try to update the values using "DataGrid1_UpdateCommand()"
The FindByApplID does't find the row.
It looks like the 'DataSet12.Appl.Rows.InsertAt(dr, 0)' doesn't insert.
But it show up in the grid.

The msdn example is

But add new row is added.
Private Sub LinkButton1_Click(ByVal sender As System.Object,
ByVal e As
System.EventArgs) Handles LinkButton1.Click

Dim dr As DataRow = DataSet12.Appl.NewRow()
dr.Item("Description") = "Enter Description here"
DataSet12.Appl.Rows.InsertAt(dr, 0)

''' The inserts into a table using a indentity field as primary

''' SqlDataAdapter1 insert command
'''' INSERT INTO Appl(Description, Wav)
''' VALUES (@Description, @Wav); SELECT ApplID,
''' Description, Wav FROM Appliance

Dim Index As Integer = dr.Item("ApplID") ''' Does get a new
identity value back

'' I must not be committing/binding/something here

DataGrid1.EditItemIndex = 0
End Sub

Private Sub DataGrid1_UpdateCommand(ByVal source As Object,
ByVal e
As System.Web.UI.WebControls.DataGridCommandEventArgs )
Handles DataGrid1.UpdateCommand

Dim key As String = DataGrid1.DataKeys(e.Item.ItemIndex).ToString()
Dim desc, watts As String
Dim tb As TextBox
tb = CType(e.Item.Cells(1).Controls(0), TextBox)
desc = tb.Text
If desc <"Enter Description here" And desc.Trim.Length 0 Then
tb = CType(e.Item.Cells(2).Controls(0), TextBox)
If tb.Text.Trim.Length <0 And IsNumeric(tb.Text.Trim) Then
watts = tb.Text
Dim r As DataSet1.ApplianceRow

r = DataSet12.Appliance.FindByApplianceID(key) '
*********** not found

r.Description = desc
r.Watts = watts
DataGrid1.EditItemIndex = -1
End If
End If

End Sub

Thanks in advance

Aug 8 '06 #1
0 1062

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Steve Donnor | last post: by
7 posts views Thread by Zachary Hilbun | last post: by
1 post views Thread by Henry | last post: by
15 posts views Thread by JIM.H. | last post: by
4 posts views Thread by jay | last post: by
12 posts views Thread by Bishoy George | last post: by
12 posts views Thread by Graham Blandford | last post: by
2 posts views Thread by Peter Van Wilrijk | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.