Steps involved to fill a DataSet
What are steps involved to fill a DataSet.
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Dorababu MekaPosted Sep 21, 2012, 7:04 AM
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);