. , dataview dataview . , dataview.
1. , dataadapter
:
I) :
SqlConnection con=new SqlConnection("Data Source=servername;Database=dbname;Integrated Security=true");
(or)
SqlConnection con=new SqlConnection("Data Source=servername;Database=dbname;user id=xxx;pwd=xxx");
II) :
SqlDataAdapter sda=new SqlDataAdapter("query",con);
2. DataSet :
DataSet ds=new DataSet();
sda.fill(ds);// filling sda data into dataset using fill method of adapter class
Step 3: Check the dataset is not empty or not. If not empty, create a DataView object and fill it with a sorted option and a combobox:
if(ds.Tables[0].rows.count>0)
{
DataView dv=new DataView();
dv.Table=ds.Tables[0];
dv.sort="columnname";
DropDownList1.DataSource=dv;
DropDownList1.DataTextField="columnname";
DropDownList1.DataBind();
DropDownList1.Items.Insert(0,"select");
}
source
share