Sunday, 30 December 2012 13:55

using DataSet in application

Written by 
Rate this item
(0 votes)

we can use DataSet to populate DataList or
GridView efficiently.DataSet is the best
option for accessing rows of tables.

Following example shows how to use DataSet
in application -

here DataSet is filled with data by the
DataAdapter and then is set as a DataSource
for the DataList control.here i used MySql
database.

using System;
using MySql.Data;
using MySql.Data.MySqlClient;

namespace DataSet {
public partial class liststuds : System.Web.UI.Page
{
MySqlCommand cmd;
MySql.Data.MySqlClient.MySqlConnection conn;
MySqlDataReader reader;
protected void Page_Load(object sender, EventArgs e)
{
string connect = "Server=localhost;Database=MySqlDb;user
id=root;password=mridul;";//local db
string query = "SELECT * from adstuds order by state,breedname";
conn = new MySql.Data.MySqlClient.MySqlConnection(connect);
conn.Open();
MySqlDataAdapter adapter = new MySqlDataAdapter(query, conn);
DataSet data = new DataSet();
adapter.Fill(data);
StudListDataList.DataSource = data;
StudListDataList.DataBind();
}}}

Read 3330 times
Super User

Email This email address is being protected from spambots. You need JavaScript enabled to view it.

Latest discussions

  • No posts to display.