ADO.Net Interview Questions and Answers
<< Previous Question Next Question >>
 Question: 2291 Page Views: 

Explain the various steps involved to fill a dataset?



Posted By: Avi Date: 8 October 2009 03:16:53 AM
 Answer:

Step-1:
Open the database connection by creating a Connection object. We can load the connection string from config file.

SqlConnection objConn = New SqlConnection(strConnectionString);
objConn.Open();

Step-2:
Create a command object with appropriate SQL command and set the connection object to this command.

SqlCommand objCommand = New SqlCommand("Select FirstName from Employees");
objCommand.Connection = objConn;

Step-3:
Create the DataAdapter object and pass the command object.

SqlDataAdapter objDataAdapter = New SqlDataAdapter();
objDataAdapter.SelectCommand = objCommand;

Step-4:
Create a DataSet object. Call the "Fill" method of the DataAdapter object and pass the DataSet object. It will load the data into the DataSet object.

DataSet objDataSet = New DataSet();
objDataAdapter.Fill(objDataSet);


Posted By: eTechPlanet


Date: 8 October 2009 03:16:53 AM
Post a better Answer if you have
 
(Will show your Gravatar icon)  
  Country flag

Loading
Enter the text as shown in the image vDN71Y
Related Questions
ADO.Net : How do you check number of rows affected by update query?

How do you check number of rows affected by update query?

ExecuteNonQuery Method on SqlCommand returns number of rows affected.
Category: ADO.Net Date: 10/14/2010 5:01:48 AM
ADO.Net : Is it possible to use single code to work with different data providers?

Is it possible to use single code to work with different data providers?

Yes. By using IDbConnection, IDbCommand(you can create command object using IDbConnection.CreateComm....
Category: ADO.Net Date: 10/14/2010 5:01:48 AM
ADO.Net : Can DataGridView use DataSet as data source?

Can DataGridView use DataSet as data source?

Yes
Category: ADO.Net Date: 10/14/2010 4:09:47 AM
ADO.Net : What is Entity Framework?

What is Entity Framework?

ADO.NET Entity Framework is an object-relational mappin framework
Category: ADO.Net Date: 10/14/2010 4:09:47 AM
ADO.Net : Can you edit XML data using XPathNavigator created from XPathDocument class?