Powered by Blogger.

Sunday, February 23, 2014

Populate dataset with data adapter and XML in Asp.Net




In this post we will discuss how we can populate a dataset with data adapter in asp.net.

Also check out:

- Data access block of Microsoft enterprise library 6.0 using inline sql statement

- Export gridview data to excel sheet in Asp.net

- Triggers in sql server 2008

Populate from Data Adapter:

We can fill the dataset by calling the Fill() method of the Data Adapter class. Below is the full code that will fill the database.

string conn = "You connection string will goes here";

string strSQL = "SELECT * FROM EMPLOYEES";

SqlConnection conn = new SqlConnection(conn);

SqlDataAdapter da = new SqlDataAdapter(strSQL, conn);

DataSet ds = new DataSet();

da.Fill(ds, "Employees");

Also you can call the fill method like below:

da.Fill(ds);

But when you want to retrieve then you have to retrieve using the index like ds.Tables[0].

But in the above method you can retrieve like ds.Tables["Employees"].

Populate from XML:

To load XML into a DataSet class, we have to call the ReadXML() method like below:

DataSet ds = new DataSet();

ds.ReadXml("C:\\Employees.xml");



0 comments

Post a Comment