Code for calling a stored procedure in Asp.net

Source: Internet
Author: User

After debugging,

<% @ Import namespace = "system. Data" %>
<% @ Import namespace = "system. Data. sqlclient" %>
<SCRIPT runat = "server" Language = "VBScript">
Sub on_click (byval sender as object, byval e as eventargs)
Dim conn as new sqlconnection ()
Dim objreader as sqldatareader

Dim I as integer
'Conn. connectionstring = "Data Source =.; Integrated Security = sspi; initial catalog = xscj; packet size = 4096" error
'SQL Server database connection string
Conn. connectionstring = "Data Source = ..; initial catalog = data; Integrated Security = false; user id = sa; Pwd =; packet size = 4096"
Conn. open ()
'Create a sqlcommand object
Dim cmd as new sqlcommand ()
Cmd. Connection = Conn
Cmd. commandtype = commandtype. storedprocedure 'set the command type of the sqlcommand object to Stored Procedure
Cmd. commandtext = "showscore" 'specifies the stored procedure to be executed.
Cmd. Parameters. Clear ()
'Add student ID and Course name Parameters
Cmd. Parameters. Add (New sqlparameter ("@ No", sqldbtype. varchar, 10 ))
Cmd. Parameters. Add (New sqlparameter ("@ course", sqldbtype. varchar, 20 ))
'Assign values to parameters
Cmd. parameters ("@ No"). value = Stu. Text
Cmd. parameters ("@ course"). value = KC. Text
'Execute the Stored Procedure
Objreader = cmd. executereader ()
'Read and display data
Response. Write ("<H2 align = center> result table for executing the Stored Procedure showsocret </H2> ")
Response. Write ("<Table align = center border = 2> <tr align = center> ")
For I = 0 to objreader. fieldcount-1 'displays the table field name
Response. Write ("<TD>" & objreader. getname (I) & "</TD> ")

Next
While objreader. Read ()
Response. Write ("<tr> ")
For I = 0 to objreader. fieldcount-1
Response. Write ("<TD>" & objreader. getvalue (I) & "</TD> ")
Next
Response. Write ("<tr> ")
End while
Response. Write ("</table> ")
Objreader. Close () 'Close the datareader object
Conn. Close () 'Close the data connection

End sub
</SCRIPT>

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.