📄 webform1.aspx.vb
字号:
Public Class WebForm1
Inherits System.Web.UI.Page
Protected WithEvents conn As New System.Data.SqlClient.SqlConnection
Protected WithEvents com As New System.Data.SqlClient.SqlCommand
Protected rd As System.Data.SqlClient.SqlDataReader
#Region " Web 窗体设计器生成的代码 "
'该调用是 Web 窗体设计器所必需的。
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
'注意: 以下占位符声明是 Web 窗体设计器所必需的。
'不要删除或移动它。
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: 此方法调用是 Web 窗体设计器所必需的
'不要使用代码编辑器修改它。
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
conn.ConnectionString = "Persist Security Info=False;Initial Catalog=Northwind;Data Source=localhost;Integrated Security=SSPI;"
com.Connection = conn
'使用存储过程
com.CommandType = CommandType.StoredProcedure
'给出存储过程的名字
com.CommandText = "EmployeeName"
'给出存储过程的输入参数@Title,并赋值
com.Parameters.Add("@Title", SqlDbType.NVarChar, 30)
com.Parameters("@Title").Value = "Sales Representative"
'给出存储过程的输出参数@Count
com.Parameters.Add("@Count", SqlDbType.Int)
'指明@Count参数为输出参数
com.Parameters("@Count").Direction = ParameterDirection.Output
conn.Open()
'创建数据读取器DataReader对象
rd = com.ExecuteReader()
'读取第一数据列的列名,并显示出来
Response.Write(rd.GetName(0))
Response.Write("<UL>")
'移动数据指针
While (rd.Read())
'读取当前数据行的第一列,并显示出来
Response.Write("<LI>" & rd.GetString(0))
'读取当前数据行的第二列,并显示出来
Response.Write("<LI>" & rd.GetString(1))
End While
Response.Write("</UL>")
Response.Write("The count is " & com.Parameters("@Count").Value)
'关闭数据读取器DataReader对象
rd.Close()
conn.Close()
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -