Philip Townsend said:
Is there any way to manually add a record to a dataset? In my case, I
may need to populate the dataset from a stored procedure or xml file,
but in some cases I may need to manually add an additional record or
row. Any suggestions? Thanks!
This is code that is used in one of the data templates in Web Matrix,
in order to add an empty row to a datagrid (for inserting a new record)
Dim myCommand As New OleDBDataAdapter(SelectCommand,
myConnection)
Dim ds As New DataSet()
myCommand.Fill(ds)
' add a new blank row to the end of the data
Dim rowValues As Object() = {0, "", "","","",""}
ds.Tables(0).Rows.Add(rowValues)
' figure out the EditItemIndex, last record on last page
Dim recordCount As Integer = ds.Tables(0).Rows.Count
If recordCount > 1 Then
recordCount -= 1
DataGrid1.CurrentPageIndex = recordCount \
DataGrid1.PageSize
DataGrid1.EditItemIndex = recordCount Mod DataGrid1.PageSize
End If
' databind
DataGrid1.DataSource = ds
DataGrid1.DataBind()