Solved 2008 select query in datatable and display in datagridview

Posted on 2009-04-14
Last Modified: 2013-11-26
I already have datatable fill with data.
i need code in 2008 to do select query in datatable and display in datagridview.
Question by:aarontham
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
  • 3
  • 2
  • 2
LVL 12

Expert Comment

ID: 24144639
I only have c# installed here but it should be easy to port from:

 DataSet1 ds = new DataSet1();
 BindingSource bindSource = new BindingSource();
 bindSource.DataSource = ds;
 bindSource.DataMember = "DataTable1";
 this.dataGridView1.DataSource = bindSource;
LVL 12

Expert Comment

ID: 24144646
sorry forgot to add you can use filter for the same effect as doing a select.

bindSource.Filter = "MyColumnName > 5";
LVL 53

Expert Comment

ID: 24145082
You can also perform a linq-query to get your result from the datatable into your datagridview.

Dim Query = From i In YourDataTable.AsEnumerable() _
         Where i.Field(Of String)("YourField") = "Status"

DataGridView_Customer.DataSource = Query.AsDataView()

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.


Author Comment

ID: 24145165
hi Dhaest:

i don't understand on the Query part. below is my code help to modify to use your code.

Public rsName As New DataTable
Dim custRows() As DataRow = rsName.Select("CusName like  '%" & (TextBox38.Text) & "%'")
LVL 53

Expert Comment

ID: 24145209
Dim Query = From i In rsName.AsEnumerable() _
         Where SqlMethods.Like(i.CusName, "%" & TextBox38.Text & "%")

Author Comment

ID: 24145284
hi Dhaest,

Do work. have error on SqlMethods

it say SqlMethods not declare and Where not declare.
LVL 53

Accepted Solution

Dhaest earned 500 total points
ID: 24145338
Imports System.Linq
Imports System.Data.Linq.SqlClient

        Dim TextBox38 As TextBox = New TextBox
        TextBox38.Text = ""

        Dim rsName As New DataTable
        rsName.Columns.Add(New DataColumn("CusName"))
        Dim Query = From i In rsName.AsEnumerable() _
         Where SqlMethods.Like(i("CusName"), "%" & TextBox38.Text & "%")

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

It’s quite interesting for me as I worked with Excel using for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

734 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