You are here:   Home
Register   |  Login

Captured Technology - Blog

Minimize

Binding a DataSet to a DataGrid in ASP.Net

by Steve Patterson on Friday, March 13, 2009 1:33 PM

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

Author
Steve Patterson

Latest technology news.

4 comment(s) so far...

Anonymous 3/16/2009

Thanks very much for this post! Was very helpful for me!

 
Anonymous 3/17/2009

I appreciate the fact that you are letting us see the previews<br>

 
Anonymous 3/26/2009

thanks

 
Anonymous 12/22/2011

Define in the Asp .net because in the post described the all the features in the post how to work and used in this technology so that can be able to understand properly.

FaceBook

Minimize

Mobile Version

Minimize
Add CapturedTech - Technology Mippin widget

Translate

Minimize

Sponsors

Minimize

Categories

Minimize

Bloggers

Minimize
Bloggers - Meet Millions of Bloggers

u comment, i follow