Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Insert method of TableAdapter not working?

Tags:

c#

ado.net

I'm using ADO.NET in my C# project. In my form I added a SourceBinding element from my toolbox in VS2010. I set the connection to the table of my dataset. It creates a DataAdapter automaticly for my.

I want to insert a record, so I call the Insert() method of the DataAdapter. But when I view my database data, it doesn't have any new records...

orderID = this.orderTableAdapter.Insert("", "", 
                (int)OrderStatus.IN_CONSTRUCTION, DateTime.Now);

Or do I need to insert it manually with the SqlCommand???

like image 672
Stijn Leenknegt Avatar asked Dec 28 '10 23:12

Stijn Leenknegt


People also ask

How to Update TableAdapter in c#?

Call the adapter's Update method in a try / catch block. If an exception is caught, locate the data row that caused the error. Reconcile the problem in the data row (programmatically if you can, or by presenting the invalid row to the user for modification), and then try the update again (HasErrors, GetErrors).

What is Tableadapter in C#?

TableAdapters are designer-generated components that connect to a database, run queries or stored procedures, and fill their DataTable with the returned data. TableAdapters also send updated data from your application back to the database.

What is Tableadapter in VB net?

TableAdapters provide communication between your application and a database. They connect to the database, run queries or stored procedures, and either return a new data table or fill an existing DataTable with the returned data. TableAdapters can also send updated data from your application back to the database.


1 Answers

The table adapters are designed to be used with a dataset, to help you get data in and out of the DB using this dataset.

Idea is that you can use the Dataset.NewYourTableNameRow() to create a new row for your dataset, then populate its fields and then call DataSet.AddYourTableNameRow(row) to put it in the dataset.

Now you can orderTableAdapter.update(DataSet) to transmit that new row into the database.

To delete or update a row, you would select it first into your dataset, perform a change to the object, then call the .update(ds) on the appropriate table adapter to send it back down.

like image 76
Spence Avatar answered Sep 20 '22 12:09

Spence