Steps involved to fill a DataSet
What are steps involved to fill a DataSet.
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Dorababu MekaRank #457 · 5.5K reputationPosted Sep 21, 2012, 3:04 AM EDT
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);