Yesterday, there was an old classmate in a long time, and suddenly asked how to call the SQL stored procedure in VB. At that time, because there was no information in his hand, it didn't load SQL on the machine. He immediately wrote a Asp code written in the early years, nor did you know. Holding a responsible attitude, just a little free, I did a test: (Saying, the N hasn't used VB, I didn't know how to join the AdoDB type library, I fill an ADODC control, Juji ~ `` `) Private su examplebutton_click () Dim Sqlconn as new adodb.connectiondim sqlcmd as new adod.com.Commanddim myparam as adoDb.Parameterdim Sqlrs as adoDb.recordsetdim Sqlcmdstr As String
Sqlconn.open "driver = {SQL Server}; server = 127.0.0.1; database = master; uid = sa; pwd = password I will not tell others :)" Sqlcmd.activeConnection = SqlConnsqlcmd.commandtext = "sp_executesql "sqlCmd.CommandType = adCmdStoredProcsqlCmdStr =" SELECT * FROM sysmessages WHERE error> = 100 AND error <= 120 "Set myParam = sqlCmd.CreateParameter (" @ statement ", adBSTR, adParamInput, Len (sqlCmdStr)) myParam.Value = sqlCmdStrsqlCmd. Parameters.Append myparamset SQLRS = SQLCMD.EXECUTE
Sqlrs.movefirstWhile Not Sqlrs.eof msgbox sqlrs.fields (0) .value & ",,," & SQLRS.Fields (3) .value Sqlrs.movenextwexts Sub haha, actually succeeded (can not help but self-intoxication). Although there is no technical content, but still declaration again: In fact, the most important calling process is the correctness of the parameters, such as parameter name, parameter type, etc. Fortunately, these are all information, you can check the SQL manual, or if you have patience, you can also get the right answer (haha, nonsense) through the constant trial.