Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

add rows to a dataset

Tags:

.net

vb.net

Is it possible to add rows to a dataset?

like image 672
user26087 Avatar asked Jan 06 '09 16:01

user26087


3 Answers

yes.

dim row as DataRow 
row = ds.tables(0).NewRow 
' Add Values to Row here 
ds.tables(0).rows.add(row)
like image 161
Stephen Wrighton Avatar answered Oct 06 '22 00:10

Stephen Wrighton


Yes, you can certainly add rows to the datatables in a dataset.

Check this MSDN page for a how-to. It covers both strongly typed datasets and untyped datasets.

To add a new record to a typed dataset

Declare a new instance of the typed dataset. In the following example, you declare a new instance of the CustomersRow class, assign it a new row, populate the columns with data, and add the new row to the Customers table's Rows collection:

Dim newCustomersRow As NorthwindDataSet.CustomersRow
newCustomersRow = NorthwindDataSet1.Customers.NewCustomersRow()

newCustomersRow.CustomerID = "ALFKI"
newCustomersRow.CompanyName = "Alfreds Futterkiste"

NorthwindDataSet1.Customers.Rows.Add(newCustomersRow)

To add a record to an untyped dataset

Call the NewRow method of a DataTable to create a new, empty row. This new row inherits its column structure from the data table's DataColumnCollection. The following code creates a new row, populates it with data, and adds it to the table's Rows collection.

Dim newCustomersRow As DataRow = DataSet1.Tables("Customers").NewRow()

newCustomersRow("CustomerID") = "ALFKI"
newCustomersRow("CompanyName") = "Alfreds Futterkiste"

DataSet1.Tables("Customers").Rows.Add(newCustomersRow)
like image 25
lc. Avatar answered Oct 06 '22 00:10

lc.


No. But I suspect you mis-worded your question.

You can add rows to a dataTABLE. A Dataset is made up of DataTables (or is empty).

In order to add rows to a DataTable, you first make the DataRow and then .Add it to the DataTable

like image 31
David Avatar answered Oct 05 '22 23:10

David