Click here to Skip to main content
15,901,284 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to query over a datagridview.
Can anyone please tell me how to do this?

Thanks in advance.
Posted
Comments
Sandeep Mewara 8-Jun-12 7:26am    
What do you mean by 'query over datagridview'?
sahabiswarup 9-Jun-12 4:30am    
there is a datagridview in my widows form, i have bind this datagridview with a datatable. But now i want to sort this datagridview using Query.

Not sure about your requirement, see if this helps:
http://stackoverflow.com/questions/308085/how-to-query-a-datagridview-using-linq[^]
 
Share this answer
 
Comments
sahabiswarup 8-Jun-12 6:19am    
i have seen this, but this is not helpful.
for binding the grid you can use Datasource and Databind() method.

you can use following things to bind your query in Grid.
string s = "select fileds from table name";
SqlDataAdapter ad = new SqlDataAdapter(s,connection object);
DataSet ds = new DataSet();
ad.Fill(ds);

if (ds.Tables[0].Rows.Count != 0)
{
         gridview1.datasource=ds;
         gridview1.databind();
}






hope this will help you, if not please Post it.
 
Share this answer
 
v2
Thanks Mits Machhi for your valuable comment.
I have tried Dataview and solved this issue.

Please chek this Below:

string Name = "Adrian";
DataView dv = new DataView(dt);
dv.RowFilter = "Name='" + Name + "'";
dataGridView1.DataSource = dv;
 
Share this answer
 
v2
Comments
sahabiswarup 9-Jun-12 4:33am    
in this "dt" dataGridView source is binded; i just query over that "dt" datatable and store the result into dv Dataview and bind it with dataGridView
If your requirement is to find a cell containing a given text then I think the Code example given in my answer here DataGridView Find String[^] may be helpful.
 
Share this answer
 
Comments
sahabiswarup 9-Jun-12 4:31am    
Thanks..VJ
VJ Reddy 9-Jun-12 4:33am    
You're welcome and thank you for the response :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900