欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

数据库开发013VB.NET操作SQL Server带参数的存储过程

程序员文章站 2022-05-07 14:33:24
...

数据库开发013VB.NET操作SQL Server带参数的存储过程

Imports System.Data.SqlClient
Public Class Form1
    Dim conn As SqlConnection
    Dim comm As SqlCommand
    Private Function GetConnection() As SqlConnection
        Return New SqlConnection(My.Settings.SalesConnectionString)
    End Function


    Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click

        conn = GetConnection()
        conn.Open()

        comm = New SqlCommand("sp_CheckPass", conn)
        comm.CommandType = CommandType.StoredProcedure
        comm.Parameters.Add("@CHKName", SqlDbType.VarChar, 30).Value = TextBox1.Text
        comm.Parameters.Add("@CHKPass", SqlDbType.VarChar, 30).Value = TextBox2.Text
        comm.Parameters.Add("@ISValid", SqlDbType.VarChar, 20).Direction = ParameterDirection.Output
        comm.ExecuteNonQuery()

        If comm.Parameters("@ISValid").Value = "Good" Then
            MsgBox("成功")
        Else
            MsgBox("失败")
        End If

        conn.Close()

    End Sub
End Class

 

相关标签: 数据库开发