DataSet insert problem

P

paulhux174

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/e...aGridWebControlToReadWriteData.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
-----------------------------------------------------------------------------------------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top