Free Training


C Language  |  CSS  |  MainFrame  |  VBScript  |  PHP  |  XML  |  C++ Tutorials  |  Ajax  |  JavaScript  |  CSS3  |  UML  |  jQuery  |  Microsoft AJAX

ASP.NET Tutorials

 
Home Tutorials ASP.NET
 

Managing Data with ADO.NET DataSets and C#

 

Page 4 of 2




ALFKI
Alfreds Futterkiste


ANATR
Ana Trujillo Emparedados y helados


10643
ALFKI
1997-08-25T00:00:00


10692
ALFKI
1997-10-03T00:00:00


10308
ANATR
1996-09-18T00:00:00



Note that the Customers element and the Orders elements are shown as sibling elements. If you wanted to have the Orders elements show up as children of their respective parent elements, the Nested property of the DataRelation would need to be set to true and you would add the following:

The following code shows what the resulting output would look like, with the Orders elements nested within their respective parent elements.



ALFKI

10643
ALFKI
1997-08-25T00:00:00


10692
ALFKI
1997-10-03T00:00:00

Alfreds Futterkiste


ANATR

10308
ANATR
1996-09-18T00:00:00

Ana Trujillo Emparedados y helados


(www.msdn.microsoft.com)



Using DataSet with DataAdapters to Modify Data


We can also use DataAdapters to modify data in the database. There are several properties that are available to perform these operations.

Let's see some of the properties:

ad.SelectCommand = new SqlCommand("SELECT * FROM Person",myConnection);

ad.UpdateCommand = new SqlCommand("UPDATE TABLE Person SET Name='john' WHERE PersonID = 1");

ad.DeleteCommand = new SqlCommand("DELETE TABLE Person WHERE PersonID = 1");

ad.InsertCommand = new SqlCommand("INSERT INTO PERSON VALUES('NewName') ");

All the properties are self explanatory. SelectCommand property is used to select, Update command property is used to update and so forth.

When we issue the command we can just later fill the Dataset with the DataAdatper and later we can bind the dataset to datagrid to view the result on the user interface.


Download Project Files



Read Next: Creating and consuming XML Web Services with C#



 

 

Comments



Post Your Comment:

Members Please Login
Your Name:*
e-mail ID:(required for notification)*
Image Verification: 
 
 Subscribe    

Weekly Offers

Sponsored Links