Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

C# Hot to query a DataTable and select the Row in DataGrid

Posted on 2006-07-10
4
Medium Priority
?
1,266 Views
Last Modified: 2012-06-27
I have DataTable, Columns in it are ID and Price. I am showing that Datatable using DataGrid.

Now, I have an ID and I want to query my DataTable and if I find that ID in DataTable, I wana select that record in DataGrid.


AnyHelp
0
Comment
Question by:tahir_666
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 29

Accepted Solution

by:
Gautham Janardhan earned 500 total points
ID: 17072606
You could use the datatable .select() function to do this.for this u would have to set one of ur columns in the table as a primary key

ATable.Constraints.Add(contraintname,columnname,primarykey)

then u could use Atable.select (string filter exp) to
select corresponding row

exp can be like "COLUMNNAME = VALUE"
or "COLUMNNAME < VALUE"
0
 
LVL 29

Expert Comment

by:Gautham Janardhan
ID: 17072622
add to that above if u dont set the primary key the problem would be that there is chance of returning multile rows
0
 

Author Comment

by:tahir_666
ID: 17072652
I can get the Row which I want to select....but I want to select the Row in DB grid, if found.

Anycode for selecting the Row in Datagrid???
0
 

Author Comment

by:tahir_666
ID: 17079375
Found by help of office dude :o)

dgSQL.DataSource = dtSQL2;

                for (int i = 0; i < dtSQL2.Rows.Count; i++)
                {
                    if (dtSQL2.Rows[i]["ORDER_ID"].ToString() == OrderID.ToString())
                    {
                        dgSQL.Rows[i].Selected = true;
                    }
                    else
                    {
                        dgSQL.Rows[i].Selected = false;
                    }
                }
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Progress

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question