What are the steps involved to fill a dataset? Write the code for the same?

 Posted by Rajni.Shekhar on 6/29/2012 | Category: ADO.NET Interview questions | Views: 4309 | Points: 40

Steps to fill a dataset.

a. Create a connection object.
b. Create an adapter by passing the string query and the connection object as parameters.
c. Create a new object of dataset.
d. Call the Fill method of the adapter and pass the dataset object.

using System.Data;

using System.Data.SqlClient;

SqlConnection conn = new SqlConnection("server=localhost;Database=MyDB;userid=sa;pwd=sa");
SqlDataAdapter da = new SqlDataAdapter("select * from table1", con);
DataSet ds = new DataSet();

Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Posted by: Itechsasi on: 6/29/2012 | Points: 10

When connection will open and close in dataAdapter. I heard that it is disconnected architecture.
if it is closed means while updating the dataset will open the connection again?.

Please explain about disconnected architecture.
Posted by: Rajni.Shekhar on: 6/29/2012 | Points: 10
You need to open a connection and close connection after finishing your work.
or use using (conn){
connection will be closed automatically after finishing using block.

Login to post response