How to invoke a stored procedure in Visual Basic?
In VB, you can use ADO (ActiveX Data Objects) objects to call stored procedures. Here is a simple example code:
Dim conn As Object
Set conn = CreateObject("ADODB.Connection")
conn.ConnectionString = "Provider=SQLOLEDB;Data Source=服务器名;Initial Catalog=数据库名;User ID=用户名;Password=密码"
conn.Open
Dim cmd As Object
Set cmd = CreateObject("ADODB.Command")
cmd.ActiveConnection = conn
cmd.CommandType = adCmdStoredProc
cmd.CommandText = "存储过程名"
' 设置存储过程的参数
cmd.Parameters.Append cmd.CreateParameter("参数名", adInteger, adParamInput, , 参数值)
' 执行存储过程
cmd.Execute
' 关闭连接
conn.Close
Set conn = Nothing
Set cmd = Nothing
In the code, you need to modify the connection string, stored procedure name, and parameter values according to your actual situation. Additionally, you can also add other parameters as needed.
Please note that the code above is using the old version of ADO (ADODB). In the new version of .NET, you can use ADO.NET to call stored procedures.