Answer: 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.
Example:
using System.Data;
using System.Data.SqlClient;
SqlConnection conn = new SqlConnection("server=localhost;Database=MyDB;userid=sa;pwd=sa");
conn.Open();
SqlDataAdapter da = new SqlDataAdapter("select * from table1", con);
DataSet ds = new DataSet();
da.Fill(ds);
Asked In: Many Interviews |
Alert Moderator