SQL存储过程的简单应用


在button中的代码
       Dim bh As String
        bh = InputBox("请输入要删除的行数")
        Dim sqlcom As New SqlCommand("DeleteRowProc", sqlcon)
        '将sqlcommand按存储过程传值
        sqlcom.CommandType = CommandType.StoredProcedure
        sqlcom.Parameters.Add(New SqlParameter("@noo", SqlDbType.Int) With {.Value = bh})

        '    Dim aa As New SqlParameter("@noo", SqlDbType.Int)
        '   aa.Value = bh

        Try
            sqlcon.Open()
            sqlcom.ExecuteNonQuery()
            MsgBox("success")
        Catch ex As Exception
            MsgBox("failure")
        End Try


在SQL中的存储过程

 

CREATE PROCEDURE DeleteRowProc

	@noo int
AS
BEGIN

	SET NOCOUNT ON;

	delete 员工表 where 编号=@noo
END


-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

员工信息插入模块

 

 

 Private Sub btnInsert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInsert.Click

        Dim pname As New SqlParameter("@name ", SqlDbType.VarChar, 10)
        Dim page As New SqlParameter("@age ", SqlDbType.Int, 2)
        Dim psex As New SqlParameter("@sex", SqlDbType.VarChar, 2)
        Dim pxl As New SqlParameter("@xl", SqlDbType.VarChar, 10)
        Dim pdep As New SqlParameter("@dep ", SqlDbType.VarChar, 10)
        pname.Value = txtName.Text
        page.Value = txtAge.Text
        psex.Value = txtSex.Text
        pxl.Value = cmbXl.Text
        pdep.Value = cmbDepartment.Text
        Dim icom As New SqlCommand("oooo", sqlcon)
        icom.CommandType = CommandType.StoredProcedure
        icom.Parameters.Add(pname)
        icom.Parameters.Add(page)
        icom.Parameters.Add(psex)
        icom.Parameters.Add(pxl)
        icom.Parameters.Add(pdep)
        Try
            sqlcon.Open()
            icom.ExecuteNonQuery()
            MsgBox("success")
        Catch ex As Exception
            MsgBox("failure")
        End Try
    End Sub


SQL中的存储过程

 

ALTER PROCEDURE [dbo].[oooo] 
@name  varchar(10),
@age int,
@sex varchar(2),
@xl varchar(10),
@dep varchar(10)

AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

insert into dbo.[员工表](姓名,年龄,性别,学历,所属部门) values (@name,@age,@sex,@xl,@dep)

END


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值