INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

How-to

How to bind the DataSet object to Datagrid? by PankajBanga
Posted: 1 Jul 03 (Edited 24 Jul 03)


This sample refers to the System.Data.OleDb Class Library namespaces and NWIND.mdb (access database).

Imports System.Data.OleDb

        Dim strConn As String
        Dim strSQL As String
        Dim Conn As OleDbConnection

        Dim objDA As OleDbDataAdapter
        Dim objDS As New DataSet()

        Try
            'MAKE SURE TO CHANGE THE PATH OF NWIND.mdb AS PER ON YOUR MACHINE.
            'Build the Connection strings.    
            strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
                      "Data Source=C:\Program Files\Microsoft Visual Studio\VB98\NWIND.mdb"

            'Pass the Connection string to OleDbConnection object.
            Conn = New OleDbConnection(strConn)

            'Build the SQL strings.    
            strSQL = "SELECT EmployeeID, FirstName, LastName " & _
                            "FROM Employees "

            'Initialize the OleDbDataAdapter with SQL and Connection string,
            'and then use the OleDbAdapter to fill the DataSet with data.
            objDA = New OleDbDataAdapter(strSQL, Conn)
            objDA.Fill(objDS, "Employees")

            'Bind the DataSet to DataGrid.
            DataGrid1.SetDataBinding(objDS, "Employees")

        Catch Excep As System.Exception
            MessageBox.Show(Excep.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try

Back to Visual Basic (Microsoft) VB.NET FAQ Index
Back to Visual Basic (Microsoft) VB.NET Forum

My Archive

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close