Hi,
a dataset is actually a class that you can manipulate on your own through code. It uses other classes like datatables, datarows, ... If you take a look at the MSDN library on the DataGrid.DataSource property, you'll see an example on how the datasource get's filled with a dataview that's entirely made up with code. Also be sure to check out the DataSet class and the DataTable class.
Imports System.Data.SqlClient
Imports System.Configuration.ConfigurationSettings
Public Class test1
Inherits System.Web.UI.Page
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<system.diagnostics.debuggerstepthrough()> Private Sub InitializeComponent()
End Sub
Protected WithEvents dgProduct As System.Web.UI.WebControls.DataGrid
'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Dim con As String = AppSettings("ConnectionString")
Dim objSQLCon As New SqlConnection(con)
Dim cmd As SqlCommand
Dim red As SqlDataReader
Function CreateDataSource() As ICollection
Dim dt As New DataTable
Dim dr As DataRow
dt.Columns.Add(New DataColumn("Product Code", GetType(String)))
dt.Columns.Add(New DataColumn("Product Description", GetType(String)))
dt.Columns.Add(New DataColumn("Product Availability", GetType(String)))
Dim queryCode As String = "Select Prod_Code,Prod_Description,Prod_Availability from Product"
Dim objCmdCode As New SqlCommand(queryCode, objSQLCon)
Dim rdrCode As SqlDataReader
Dim row As DataRow
objSQLCon.Open()
rdrCode = objCmdCode.ExecuteReader
Do While rdrCode.Read
row = dt.NewRow()
row(0) = rdrCode.GetValue(0)
row(1) = rdrCode.GetValue(1)
row(2) = rdrCode.GetValue(2)
dt.Rows.Add(row)
Loop
objSQLCon.Close()
Dim dv As New DataView(dt)
Return dv
End Function 'CreateDataSource
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not IsPostBack Then
' Load this data only once.
dgProduct.DataSource = CreateDataSource()
dgProduct.DataBind()
End If
End Sub
End Class
<form id="frmTest" method="post" runat="server">
<asp:datagrid id="dgProduct" runat="server" width="400px" height="128px" autogeneratecolumns="true" xmlns:asp="#unknown">
</asp:datagrid>
</form>