Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# DataAdapter and DataSet with multiple table

I have read from many places that it is possible to fill a DataSet with multiple tables using a DataAdapter. It also does not say whether a single Update call can update all the tables in the DataSet.

Can someone help me figure out how this can be done?

It seems like there isn't any ( i tried finding online ) examples on how to do it except for one that changes the SelectCommand on the DataAdapter before the second fill. But I feel this method defeats the purpose of the DataAdapter.

From what I figure, perhaps a single DataAdapter can only handle a single database table and Update only works on that table. Hence a multi-table DataSet will require respective DataAdapters call their Update to fully update the DataSet. Is this the case?

Finally, will foreign key relations and contraints hold in a DataSet (cascade delete, cascade update) automatically?

Maybe a link to an example or tutorial might help. Many thanks!

like image 427
Jake Avatar asked Jan 01 '11 16:01

Jake


People also ask

What C is used for?

C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...

What is the full name of C?

In the real sense it has no meaning or full form. It was developed by Dennis Ritchie and Ken Thompson at AT&T bell Lab. First, they used to call it as B language then later they made some improvement into it and renamed it as C and its superscript as C++ which was invented by Dr. Stroustroupe.

Is C language easy?

C is a general-purpose language that most programmers learn before moving on to more complex languages. From Unix and Windows to Tic Tac Toe and Photoshop, several of the most commonly used applications today have been built on C. It is easy to learn because: A simple syntax with only 32 keywords.

How old is the letter C?

The letter c was applied by French orthographists in the 12th century to represent the sound ts in English, and this sound developed into the simpler sibilant s.


1 Answers

  1. Yes it is true that, Single Adapter for single table.But

  2. You can use Use table adapter manager for saving all at once, table adapter manager can have many individual adapters and you can call save for all. like, So no need to call save multiple time also it has other features too.

    public void SaveWithManager()
    {
    DataSet1TableAdapters.TableAdapterManager mgr1 = new DataSet1TableAdapters.TableAdapterManager();
    DataSet1TableAdapters.Table1TableAdapter taTbl1 = new DataSet1TableAdapters.Table1TableAdapter();
    DataSet1TableAdapters.Table2TableAdapter taTbl2 = new DataSet1TableAdapters.Table2TableAdapter();
    
    
    mgr1.Table1TableAdapter = taTbl1;
    mgr1.Table2TableAdapter = taTbl2;
    mgr1.UpdateOrder = DataSet1TableAdapters.TableAdapterManager.UpdateOrderOption.InsertUpdateDelete; 
    mgr1.UpdateAll(your dataset);
    

    }

  3. Finally cascade update delete is handled in dataset. You can view properties of relation and various options for cascade.(Typed dataset)

like image 179
indiPy Avatar answered Sep 21 '22 15:09

indiPy