Link to home
Start Free TrialLog in
Avatar of aarontham
aarontham

asked on

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

I already have datatable fill with data.
i need code in vb.net 2008 to do select query in datatable and display in datagridview.
Avatar of wht1986
wht1986
Flag of United States of America image

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;
sorry forgot to add you can use filter for the same effect as doing a select.

bindSource.Filter = "MyColumnName > 5";
Avatar of Dirk Haest
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()

Avatar of aarontham
aarontham

ASKER

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) & "%'")
Dim Query = From i In rsName.AsEnumerable() _
         Where SqlMethods.Like(i.CusName, "%" & TextBox38.Text & "%")
hi Dhaest,

Do work. have error on SqlMethods

it say SqlMethods not declare and Where not declare.
ASKER CERTIFIED SOLUTION
Avatar of Dirk Haest
Dirk Haest
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial