0
votes

Using Visual Express 2010 I've added a DataGridView and have bound it to a database table. I need to add a row to this table but how?

I've got the following

fuelStopsTableAdapter

fuelStopsDataSet1 (this consists of the columns date, cost, car-string)

I believe I have to create a DataRow from my DataSet then add that to the DataSet? Then update the table using the DataSet?

Would appreciate some guidance.

1

1 Answers

3
votes

Create a DataRow object by the DataTable.NewRow method by the dataset and assign values to DataRow columns and add to DataTable.

DataRow dr = dataset.Tables[0].NewRow();
dr["ColumnName1"] = "Some Value 1";
dr["ColumnName2"] = "Some Value 2";
dataset.Tables[0].Rows.Add(dr);

DataTable.NewRow

You must use the NewRow method to create new DataRow objects with the same schema as the DataTable. After creating a DataRow, you can add it to the DataRowCollection, through the DataTable object's Rows property. When you use NewRow to create new rows, the rows must be added to or deleted from the data table before you call Clear, Reference.