Server| stored procedure yesterday, an old classmate who had never met, suddenly asked how to call SQL stored procedures in VB.
At that time because there is no information on the hand, the machine also did not install SQL, then sent an early written paragraph of ASP code, do not know how to do.
With a responsible attitude and just a little free, he did a test:
(ashamed to say, n long no use of VB, incredibly do not know how to join the ADODB type library, add a adodc control, shame ~ "")
Private Sub Examplebutton_click ()
Dim sqlconn as New ADODB. Connection
Dim SQLCMD as New Adodb.command
Dim Myparam as ADODB. Parameter
Dim Sqlrs as ADODB. Recordset
Dim Sqlcmdstr as String
Sqlconn.open "Driver={sql server};server=127.0.0.1;database=master;uid=sa;pwd= password I will not casually tell others:"
Sqlcmd.activeconnection = sqlconn
Sqlcmd.commandtext = "sp_executesql"
Sqlcmd.commandtype = adCmdStoredProc
SQLCMDSTR = "SELECT * from sysmessages WHERE error>=100 and error<=120"
Set myparam = Sqlcmd.createparameter ("@statement", Adbstr, adParamInput, Len (SQLCMDSTR))
Myparam.value = Sqlcmdstr
SqlCmd.Parameters.Append Myparam
Set Sqlrs = Sqlcmd.execute
Sqlrs.movefirst
While not sqlrs.eof
MsgBox sqlrs.fields (0). Value & ",,," & Sqlrs.fields (3). Value
Sqlrs.movenext
Wend
End Sub
Haha, incredibly successful (can not help but a narcissistic).
Although there is no technical content, but again to affirm:
In fact, the most important thing to call stored procedures is the correctness of parameters, such as parameter names, parameter types, and so on.
Fortunately, these are all data can be checked, you can check the SQL manual, or if you have patience, you can try to get the right answer (haha, nonsense).