469,631 Members | 1,305 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,631 developers. It's quick & easy.

DataSet insert problem

Hi,
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
http://msdn.microsoft.com/library/en...asp?frame=true

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
key.

''' 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
DataGrid1.DataBind()
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
SqlDataAdapter1.Update(DataSet12)
DataGrid1.EditItemIndex = -1
DataGrid1.DataBind()
End If
End If

End Sub

Thanks in advance
-----------------------------------------------------------------------------------------------------

Aug 8 '06 #1
0 1015

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 gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.