更新时间:2023-10-08 08:38:04
从VB创建存储过程的过程完全相同从SSMS开始 - 它只是一系列创建它的SQL命令。
所以你做通常的事情:创建一个SqlConnection对象,打开它。在该连接上创建一个SqlCommand对象,并为其创建SP create命令作为命令字符串:
Creating a stored procedure from VB is exactly the same process as from SSMS - it is just a series of SQL commands which creates it.
So you do the usual things: create a SqlConnection object, open it. Create a SqlCommand object on that connection, and give it the SP create commands as the command string:
Using con As New SqlConnection(strConnect)
con.Open()
Dim strCreateSP As String = "CREATE PROC [dbo].Sample
@ID INT
AS
BEGIN
SELECT * FROM myTable WHERE iD=@ID;
END"
Using com As New SqlCommand(strCreateSP, con)
com.ExecuteNonQuery()
End Using
End Using
创建表是完全相同的过程,但使用CREATE TABLE命令而不是CREATE PROC。
Creating a table is exactly the same procedure, but with CREATE TABLE commands instead of CREATE PROC.