Prevent the ascending order in datagridview

Posted by Agopi.Net under C# on 9/10/2012 | Points: 10 | Views : 1145 | Status : [Member] | Replies : 2
Hi,

In database the data's are in normal order. But while view in datagridview it has been getting ascending. I want the data's as it is in database. How can change this in C# for windows application.

adp = new OleDbDataAdapter("select * from food_test", conn);

ds = new DataSet();

adp.Fill(ds);

dataGridView1.DataSource = ds.Tables[0];


Regards,
Gopi A




Responses

Posted by: Ranjeet_8 on: 9/10/2012 [Member] [MVP] Gold | Points: 25

Up
0
Down
try this,

adp = new OleDbDataAdapter("select * from food_test orderby YourColumn_Name asc", conn);
// Set "asc" or "desc" with the column name in above query. "Asc" for Ascending order and "Desc" for Descending order
ds = new DataSet();

adp.Fill(ds);

dataGridView1.DataSource = ds.Tables[0];


Agopi.Net, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Naraayanan on: 9/10/2012 [Member] Starter | Points: 25

Up
0
Down
Hi,
Check your database...
or
Try this code..
dataGridView1.SortOrder = SortOrder.None;


Regards,
Lakshmi Naraayanan.S
http://dotnettechrocks.blogspot.in/
http://abaprocker.blogspot.com/

Agopi.Net, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response