Click here to hide categories Click here to show left categories

User: Home          welcome : Guest          Log In / Register here     




ADO.NET interview questions: - How to add/remove row is in “Data Table” object of “Dataset”? How to load multiple tables in a Dataset & adding relation between tables in a Dataset?

“Data table” provides “NewRow” method to add new row to “Data Table”. “Data Table” has “DataRowCollection” object that has all rows in a “Data Table” object. Following are the methods provided by “DataRowCollection” object: -

Add
Adds a new row in Data Table

Remove
It removes a “Data Row” object from “Data Table”

Remove At
It removes a “Data Row” object from “Data Table” depending on index position of the “Data Table”.

Load multiple tables in a Dataset: -

objCommand.CommandText = "Table1"

objDataAdapter.Fill(objDataSet, "Table1")

objCommand.CommandText = "Table2"

objDataAdapter.Fill(objDataSet, "Table2")


Above is a sample code, which shows how to load multiple “Data Table” objects in one “Dataset” object. Sample code shows two tables “Table1” and “Table2” in object ObjDataSet.

lstdata.DataSource = objDataSet.Tables("Table1").DefaultView


In order to refer “Table1” Data Table, use Tables collection of Datasets and the Default view object will give you the necessary output.

Adding relation between tables in a Dataset: -

Dim objRelation As DataRelation

objRelation=New

DataRelation("CustomerAddresses",objDataSet.Tables("Customer").Columns("Custid")

,objDataSet.Tables("Addresses").Columns("Custid_fk"))

objDataSet.Relations.Add(objRelation)


Relations can be added between “Data Table” objects using the “Data Relation” object. Above sample, code is trying to build a relationship between “Customer” and “Addresses” “Data table” using “Customer Addresses” “Data Relation” object.

See the following ADO.NET interview questions video on dataset is a disconnect while datareader is connected: -

Helpful Website Url
http://questpond.com/
Share this article   |    Print    |    Article read by 834 times
Author:
Shivprasad koirala Koirala
I am a Microsoft MVP for ASP/ASP.NET and currently a CEO of a small E-learning company in India. We are very much active in making training videos , writing books and corporate trainings. Do visit my site http://www.questpond.com for .NET, C# , design pattern , WCF , Silverlight , LINQ , ASP.NET , ADO.NET , Sharepoint , UML , SQL Server training and Interview questions and answers
Related Articles: No related article
Related Interview Questions: No related interview question