Use Stored procedures to pass parameters from web pages

Source: Internet
Author: User
First, create a stored procedure in the following format:
Creat procedure sp_CustomersByState @ region nvarchar (15)
AS
Select CustomerID, CompanyName from MERS
Where region = @ region Order by CompanyName
RETURN
Compile the program code:
In the C # code, we will use the new class, System. Data. SqlClient. Parameter. Objects of this class are designed to represent parameters in the stored procedure. Therefore, the constructor needs to know the name, data type, and the size of the discussed parameters.
<% @ Import namespace = "System. Data" %>
<% @ Import namespace = "System. Data. SqlClient" %>
<Html>
<Head> <title> Using Stored Procedures With Parameters </title> <Body>
<Form runat = "server" method = "post">
Enter a State Code:
<Asp: Textbox id = "txtRegion" runat = "server"/>
<Asp: Button id = "btnSubmit" runat = "server"
Text = "Search" OnClick = "Submit"/>
<Br/>
<Asp: DataGrid id = "dgOutput" runat = "server"/>
</Form>
</Body>
</Html>
<Script language = "c #" runat = "server">
Private void Submit (object sender, EventArgs e)
{
String strConnection = "Server = 224 NUMECA; database = Northwind; user id = sa; password = sa ";
SqlConnection objConnection = new SqlConnection (strConnection );

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.