📄 webform1.aspx.vb
字号:
Public Class WebForm1
Inherits System.Web.UI.Page
Protected WithEvents ListBox1 As System.Web.UI.WebControls.ListBox
Protected WithEvents txtPrice As System.Web.UI.WebControls.TextBox
Protected WithEvents txtSupplier As System.Web.UI.WebControls.TextBox
Protected WithEvents txtStock As System.Web.UI.WebControls.TextBox
Protected WithEvents txtPackage As System.Web.UI.WebControls.TextBox
Protected WithEvents SqlConnection1 As System.Data.SqlClient.SqlConnection
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.SqlConnection1 = New System.Data.SqlClient.SqlConnection()
'
'SqlConnection1
'
Me.SqlConnection1.ConnectionString = "data source=(local);initial catalog=Northwind;persist security info=False;user id" & _
"=sa;workstation id=PROTSERVER;packet size=4096"
End Sub
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
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 Me.IsPostBack Then
Dim cmd As New SqlClient.SqlCommand()
cmd.CommandText = "SELECT ProductID, ProductName FROM Products"
cmd.CommandType = CommandType.Text
cmd.Connection = SqlConnection1
SqlConnection1.Open()
Dim DS As New DataSet()
Dim DA As New SqlClient.SqlDataAdapter()
DA.SelectCommand = cmd
DA.Fill(DS, "Products")
ListBox1.DataSource = DS
ListBox1.DataMember = "Products"
ListBox1.DataTextField = "ProductName"
ListBox1.DataValueField = "ProductID"
ListBox1.DataBind()
SqlConnection1.Close()
End If
End Sub
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
Dim prodID As Integer
prodID = ListBox1.SelectedIndex
Dim cmd As New SqlClient.SqlCommand()
cmd.CommandText = "SELECT QuantityPerUnit, UnitPrice, " & _
"UnitsInStock, CompanyName " & _
"FROM Products INNER JOIN Suppliers " & _
"ON Products.SupplierID = Suppliers.SupplierID " & _
"WHERE ProductID = " & prodID
cmd.CommandType = CommandType.Text
cmd.Connection = SqlConnection1
SqlConnection1.Open()
Dim DS As New DataSet()
Dim DA As New SqlClient.SqlDataAdapter()
DA.SelectCommand = cmd
DA.Fill(DS, "Products")
txtPrice.Text = DataBinder.Eval(DS, "Tables[Products].DefaultView.[0].UnitPrice")
txtPrice.DataBind()
txtPackage.Text = DataBinder.Eval(DS, "Tables[Products].DefaultView.[0].QuantityPerUnit")
txtPackage.DataBind()
txtStock.Text = DataBinder.Eval(DS, "Tables[Products].DefaultView.[0].UnitsInStock")
txtStock.DataBind()
txtSupplier.Text = DataBinder.Eval(DS, "Tables[Products].DefaultView.[0].CompanyName")
txtSupplier.DataBind()
SqlConnection1.Close()
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -