Solved

vb.net 2008 select query in datatable and display in datagridview

Posted on 2009-04-14
7
1,235 Views
Last Modified: 2013-11-26
I already have datatable fill with data.
i need code in vb.net 2008 to do select query in datatable and display in datagridview.
0
Comment
Question by:aarontham
  • 3
  • 2
  • 2
7 Comments
 
LVL 12

Expert Comment

by:wht1986
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;
0
 
LVL 12

Expert Comment

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

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

Expert Comment

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

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

DataGridView_Customer.DataSource = Query.AsDataView()

0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

Author Comment

by:aarontham
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) & "%'")
0
 
LVL 53

Expert Comment

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

Author Comment

by:aarontham
ID: 24145284
hi Dhaest,

Do work. have error on SqlMethods

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

Accepted Solution

by:
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 & "%")
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…
This video demonstrates how to sync Microsoft Exchange Public Folders with smartphones using CodeTwo Exchange Sync and Exchange ActiveSync. To learn more about CodeTwo Exchange Sync and download the free trial, go to: http://www.codetwo.com/excha…

911 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now