Imports System.Data
Imports System.Data.SqlClient
Partial Class Admin_Default2
Inherits System.Web.UI.Page
Dim webConnect As WebConnectDB
Dim Conn As New SqlConnection
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
webConnect = New WebConnectDB 'ใช้ในการเชื่อมต่อกับฐานข้อมูล
With Conn
If .State = ConnectionState.Open Then .Close()
.ConnectionString = webConnect.strConn
.Open()
End With
If Not Page.IsPostBack() Then
BindData()
End If
End Sub
Sub BindData()
Dim Conn As New SqlConnection
Dim Com As New SqlCommand
Dim da As New SqlDataAdapter
Dim ds As New DataSet
Dim strSQL As String
strSQL = "SELECT tblTool.ToolID,tblTool.ToolName,tblTool.Qty FROM tblTool"
Com = New SqlCommand(strSQL, Conn)
With Com
.Connection = Conn
.CommandText = strSQL
.CommandType = CommandType.Text
End With
da.SelectCommand = Com
da.Fill(ds)
'*** BindData to GridView ***'
myGridView.DataSource = ds
myGridView.DataBind()
da = Nothing
Conn.Close()
Conn = Nothing
End Sub
Sub myGridView_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
Dim lblToolID As Label = CType(e.Row.FindControl("lblToolID"), Label)
If Not IsNothing(lblToolID) Then
lblToolID.Text = e.Row.DataItem("ToolID")
End If
Dim lblToolName As Label = CType(e.Row.FindControl("lblToolName"), Label)
If Not IsNothing(lblToolName) Then
lblToolName.Text = e.Row.DataItem("ToolName")
End If
Dim lblQty As Label = CType(e.Row.FindControl("lblQty"), Label)
If Not IsNothing(lblQty) Then
lblQty.Text = e.Row.DataItem("Qty")
End If
End Sub
Sub ShowPageCommand(ByVal s As Object, ByVal e As GridViewPageEventArgs)
myGridView.PageIndex = e.NewPageIndex
BindData()
End Sub
End Class