Click below for Step by Step and Interview Q & A (dotnetinter) wrote,
Click below for Step by Step and Interview Q & A
dotnetinter

QuestPond’s Interview Questions & Answers related to dataset in ADO.NET

How do you fill the dataset?

Create object of data adapter and call the fill command method of the adapter.

SqlDataAdapter objAdapter = new SqlDataAdapter(objCommand);
DataSet objDataset = new DataSet();
objAdapter.Fill(objDataset);


How can we save all data from dataset?

Dataset has “AcceptChanges” method, which commits all the changes since last time “Acceptchanges” has been executed.

How can we 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.

How can we add 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 following video on Dataset is a disconnect while datareader is connected: -



Click and see here for more basics on  ADO.NET.
Tags: ado.net basics, ado.net interview questions, ado.net training, csharp interview questions, dataset, how to learn ado.net, it interview questions with answers, programming interview questions, step by step ado.net
Subscribe

  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments