Ads

Captured Technology - Blog

Binding a DataSet to a DataGrid in ASP.Net

Binding a DataSet to a DataGrid in ASP.Net

I am in the process of enhancing the functionality of an ASP.Net application that I inherited and today I needed to display a grid of related data below an entry form on a page. Some of the functionality was present on a different page following the style the original programmer implemented. A database function to return a Datasource did not exist within the data class so that was my first step. I found this great code below showing the basic syntax of binding a dataset to a datagrid in ASP.Net which was helpful.

Imports System.Data
Imports System.Data.OleDb

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    ' create a connection string
    Dim connString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Northwind.mdb"
    Dim myConnection As OleDbConnection = New OleDbConnection

    myConnection.ConnectionString = connString

    ' create a data adapter
    Dim da As OleDbDataAdapter = New OleDbDataAdapter("Select * from Customers", myConnection)

    ' create a new dataset
    Dim ds As DataSet = New DataSet

    ' fill dataset
    da.Fill(ds, "Customers")

    ' Attach DataSet to DataGrid
    DataGrid1.DataSource = ds.DefaultViewManager

End Sub

Blog Directory

Latest technology news.
 Patrick Stevens
 554  246482  11/15/2024

Translate

Categories

Blog Calendar