⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.vb

📁 用vb.net写的基于c/s结构的进销存程序设计源代码
💻 VB
字号:
Imports System.Data.SqlClient

Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows 窗体设计器生成的代码 "

    Public Sub New()
        MyBase.New()

        '该调用是 Windows 窗体设计器所必需的。
        InitializeComponent()

        '在 InitializeComponent() 调用之后添加任何初始化

    End Sub

    '窗体重写处置以清理组件列表。
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Windows 窗体设计器所必需的
    Private components As System.ComponentModel.IContainer

    '注意:以下过程是 Windows 窗体设计器所必需的
    '可以使用 Windows 窗体设计器修改此过程。
    '不要使用代码编辑器修改它。
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents TxProductID As System.Windows.Forms.TextBox
    Friend WithEvents bnExcute As System.Windows.Forms.Button
    Friend WithEvents SqlConnection1 As System.Data.SqlClient.SqlConnection
    Friend WithEvents SqlCommand1 As System.Data.SqlClient.SqlCommand
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.Label1 = New System.Windows.Forms.Label()
        Me.TxProductID = New System.Windows.Forms.TextBox()
        Me.bnExcute = New System.Windows.Forms.Button()
        Me.SqlConnection1 = New System.Data.SqlClient.SqlConnection()
        Me.SqlCommand1 = New System.Data.SqlClient.SqlCommand()
        Me.SuspendLayout()
        '
        'Label1
        '
        Me.Label1.Location = New System.Drawing.Point(32, 16)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(88, 24)
        Me.Label1.TabIndex = 0
        Me.Label1.Text = "ProductID"
        '
        'TxProductID
        '
        Me.TxProductID.Location = New System.Drawing.Point(144, 16)
        Me.TxProductID.Name = "TxProductID"
        Me.TxProductID.Size = New System.Drawing.Size(112, 21)
        Me.TxProductID.TabIndex = 1
        Me.TxProductID.Text = "TextBox1"
        '
        'bnExcute
        '
        Me.bnExcute.Location = New System.Drawing.Point(192, 64)
        Me.bnExcute.Name = "bnExcute"
        Me.bnExcute.Size = New System.Drawing.Size(88, 24)
        Me.bnExcute.TabIndex = 2
        Me.bnExcute.Text = "Execute"
        '
        'SqlConnection1
        '
        Me.SqlConnection1.ConnectionString = "data source=YEXIAOJIAO;initial catalog=Northwind;persist security info=False;user" & _
        " id=sa;workstation id=YEXIAOJIAO;packet size=4096"
        '
        'SqlCommand1
        '
        Me.SqlCommand1.CommandText = "dbo.[GetSalesAmount]"
        Me.SqlCommand1.CommandType = System.Data.CommandType.StoredProcedure
        Me.SqlCommand1.Connection = Me.SqlConnection1
        Me.SqlCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@RETURN_VALUE", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.ReturnValue, False, CType(10, Byte), CType(0, Byte), "", System.Data.DataRowVersion.Current, Nothing))
        Me.SqlCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@ProductID", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, False, CType(10, Byte), CType(0, Byte), "", System.Data.DataRowVersion.Current, Nothing))
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
        Me.ClientSize = New System.Drawing.Size(312, 125)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.bnExcute, Me.TxProductID, Me.Label1})
        Me.Name = "Form1"
        Me.Text = "Form1"
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub bnExcute_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bnExcute.Click
        '定义变量
        Dim SalesAmount As Decimal
        '传入参数至GetSalesAmount
        SqlCommand1.Parameters("@ProductID").Value = Val(TxProductID.Text)

        '打开连接
        SqlConnection1.Open()
        '取回Stored Procedure的执行结果

        SalesAmount = CType(SqlCommand1.ExecuteScalar, Decimal)
        '先关闭连接
        SqlConnection1.Close()
        '秀出查询的结果
        MessageBox.Show(Str(SalesAmount))

    End Sub

    Private Sub SqlConnection1_InfoMessage(ByVal sender As System.Object, ByVal e As System.Data.SqlClient.SqlInfoMessageEventArgs)

    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub
End Class

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -