What’s the best way to populate a new row in a database?

Is it possible to add a new row to a database using DataSet? When I created a new DataSet and dragged the table from the database I could see that in the DataSet methods there was one called insert that in the preview showed a parameterized query almost like a stored procedure to insert data.

However, when I create a new object of that DataSet in the methods there is nothing called insert or nothing that says I can insert the data from a DataSet into a database.

From Msdn, you need to use the TableAdapter that is created:

If you do not have an instance available, instantiate the TableAdapter
you want to use.

Example:

NorthwindDataSetTableAdapters.RegionTableAdapter regionTableAdapter = 
    new NorthwindDataSetTableAdapters.RegionTableAdapter();

regionTableAdapter.Insert(5, "NorthWestern");

Check the above link for more examples.

1

Trả lời

Email của bạn sẽ không được hiển thị công khai. Các trường bắt buộc được đánh dấu *