Solved

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

Posted on 2009-04-14
7
1,233 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

Author Comment

by:aarontham
Comment Utility
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
Comment Utility
Dim Query = From i In rsName.AsEnumerable() _
         Where SqlMethods.Like(i.CusName, "%" & TextBox38.Text & "%")
0
 

Author Comment

by:aarontham
Comment Utility
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
Comment Utility
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

771 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

12 Experts available now in Live!

Get 1:1 Help Now