ASP.NET - VB.NET - Need example syntax of how to create DataTable object from SQL table AND how to bind a DataGrid to that DataTable object

Posted on 2006-04-07
Last Modified: 2006-11-18
I'm working in ASP.NET, VB.NET.  I'm looking for example syntax of the following:

1. how to create DataTable object from SQL table

2. how to bind a DataGrid to that DataTable object

Also, I'm confused as to whether or not you must use a DataSet for my question #1, or if you can do this by creating a DataTable only.

thank you!!
Question by:sah18
    LVL 3

    Accepted Solution

    Hi  sah18

    how to create DataTable object from SQL table ?
    1 create a datatable object
    2 create a sqlconnection object and adapter

    3 fill datatable with adapter.fill method

    how to bind a DataGrid to that DataTable object ?

    set datasource
    and call bind method

    Dim strCon As String
            strCon = "Data Source=TEK\sqlexpress;Initial Catalog=AdventureWorks;Integrated Security=True"
            Dim strSql As String
            strSql = "Select * from employee"

            Dim MysqlConnection As SqlConnection
            MysqlConnection = New SqlConnection(strCon)


            Dim dataadapter As SqlDataAdapter
            dataadapter = New SqlDataAdapter(strSql, MysqlConnection)

            Dim mydatatable As DataTable
            mydatatable = New DataTable


            DataGrid1.DataSource = mydatatable

    LVL 9

    Author Comment

    thank you!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
    IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    This video discusses moving either the default database or any database to a new volume.

    779 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

    18 Experts available now in Live!

    Get 1:1 Help Now