如何在vb.net方法中实现d以下sql脚本 [英] How do I implement d following sql script in a vb.net method

查看:73
本文介绍了如何在vb.net方法中实现d以下sql脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下脚本适用于我想要使用它的任务。它被执行并从sql server数据库中得到了预期的结果。但我想将其转换为在vb.net中使用的方法。

就像:

The script below was ok for the task I want to use it for. It was executed and and gave d expected result from the sql server database. But I want to convert it to a method to be used in vb.net.
Just like:

private sub employee(ByVal yyyy As string, ByVal  xxxx As string)
End sub

脚本如下所示。



The script is shown below.

Insert into Employee Values('yyyy',
(select distinct Surname from Employee where EmployeeNo=xxxx))
GO
update employeeBenefits set EmployeeNo='yyyy' where EmployeeNo='xxxx'
Go
update EmployeeCareert set EmployeeNo='yyyy' where EmployeeNo='xxxx'
Go
delete from Employee where EmployeeNo='xxxx'
GO



谢谢。


Thanks.

推荐答案

Public Sub EditEmployeeNumber(ByVal yyyy As String, ByVal xxxx As String)
    Dim strCmd As String = "Insert into Employee " & _
                            "Select distinct @Py,Surname from Employee where EmployeeNo=@Px;" & _
                            "update employeeBenefits set EmployeeNo= @Py where EmployeeNo= @Px;" & _
                            "update EmployeeCareert set EmployeeNo= @Py where EmployeeNo= @Px;" & _
                            "delete from Employee where EmployeeNo= @Px;"

    Using conn As New SqlConnection(getVHRSConstring())
        Using cmd As New SqlCommand(strCmd, conn)
            conn.Open()
            cmd.Parameters.AddWithValue("@Py", yyyy)
            cmd.Parameters.AddWithValue("@Px", xxxx)
            cmd.ExecuteNonQuery()
        End Using
    End Using
End Sub


这篇关于如何在vb.net方法中实现d以下sql脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆