To invoke the code of a stored procedure in asp.net

Source: Internet
Author: User

Debugging through the VS2005 under the

<%@ 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=;p acket size=4096 "
Conn. Open ()
' Create a SqlCommand object
Dim cmd as New SqlCommand ()
Cmd. Connection = conn
Cmd.commandtype = CommandType.StoredProcedure ' Sets the command type of the SqlCommand object as a stored procedure
Cmd.commandtext = "Showscore" Specifies the stored procedure to execute
Cmd. Parameters.clear ()
' Add school number 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 each parameter
Cmd. Parameters ("@no"). Value = Stu.text
Cmd. Parameters ("@course"). Value = kc. Text
' Execute stored Procedures
objreader = cmd. ExecuteReader ()
' Read and display data
Response.Write (

Response.Write ("<table align=center border=2 ><tr align=center >")
For i = 0 to objreader.fieldcount-1 ' Displays the name of the table field
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 DataReader object
Conn. Close () Closes 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.