Solved

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

Posted on 2009-04-14
7
1,237 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

785 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