DataTable,DataRow,DataView sorting.

Hi all,

Just check the data sorting by using dataview in below.


SqlConnection sql=new SqlConnection("Connection String");
SqlCommand cmd=new SqlCommand("SampleProcedure",sql);
cmd.CommandType=CommandType.StoredProcedure;
SqlDataAdapter da=new SqlDataAdapter(cmd);
DataSet ds=new DataSet();
da.Fill(ds);
if(ds.Tables[0].Rows.Count>0)
{
DataTable dt=new DataTable();
dt.Columns.Add("Score",typeof(double));
dt.Columns.Add("Name",typeof(string));
DataRow dr;
foreach(DataRow drow in ds.Tables[0].Rows)
{
dr = dt.NewRow();
dr["Score"] = drow ["intScore"];
dr["Name"]=drow ["strGameName"];
dt.Rows.Add(dr);
}
DataView dv=dt.DefaultView;
dv.Sort="Score desc";
DataGrid drg=new DataGrid();
drg.DataSource=dv; //drg is DataGrid
drg.DataBind();
this.Controls.Add(drg);
}

...S.VinothkumaR

4 comments:

Anonymous said...

Hello. This post is likeable, and your blog is very interesting, congratulations :-). I will add in my blogroll =). If possible gives a last there on my blog, it is about the Monitor de LCD, I hope you enjoy. The address is http://monitor-de-lcd.blogspot.com. A hug.

Unknown said...

Hi Vinoth,

I want to sort my datatable, in which one of the column datatype is double.
When i tried your code, the follwing line of code dint exist..
dt.DefaultView;
Any help would be highly appreciated.

Unknown said...

hi,
thanx for ur help , but i want to compare two dataset and display the resultant data that not in second dataset

Unknown said...

Its very interesting and informative blog dapfor. com