Imports System.Drawing
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls
Imports System.Data
Imports System.Data.SqlClient


Public Class datagrid1
    Inherits System.Web.UI.Page
    Protected WithEvents MyDataGrid As System.Web.UI.WebControls.DataGrid
    
#Region " Web Forms Designer Generated Code "
    
    'CODEGEN: This procedure is required by the Web Form Designer
    'Do not modify it using the code editor.
    Private Sub InitializeComponent()

    End Sub

#End Region

    Protected 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

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim sqlText As String = "SELECT *  FROM Authors"
        Dim ds As DataSet = GetDataSet(sqlText, "Authors")

        MyDataGrid().DataSource = ds.Tables("Authors").DefaultView
        DataBind()

    End Sub
    Function GetDataSet(ByVal sqlText As String, ByVal dsName As String) As DataSet

        Dim myConnection As New SqlConnection(Application("DBPubsConnectionString").ToString())
        Dim myCommand As New SqlDataAdapter(sqlText, myConnection)

        Dim ds As New DataSet()
        myCommand.Fill(ds, dsName)

        Return ds

    End Function

End Class
