vb/asp A stored procedure that invokes SQL Server

Source: Internet
Author: User
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).




Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.