ExecuteProcParm.aspx(示例)
1 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="ExcuteProcParm.aspx.cs" Inherits="ExcuteProcParm" %>
2
3 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
4 <html xmlns="http://www.w3.org/1999/xhtml">
5 <head runat="server">
6 <title>ExecuteProcParm</title>
7 </head>
8 <body>
9 <form id="form1" runat="server">
10 <div>
11 <table style=" 396px; height: 159px">
12 <tr>
13 <td>
14 参数名:<asp:TextBox ID="txtparm" runat="server" Width="256px" Text="id"></asp:TextBox>
15 </td>
16 </tr>
17 <tr>
18 <td>
19 参数值:<asp:TextBox ID="txtvalue" runat="server" Width="252px" Text="1"></asp:TextBox>
20 </td>
21 </tr>
22 <tr>
23 <td>
24 要执行的存储过程名:
25 </td>
26 </tr>
27 <tr>
28 <td>
29 <asp:TextBox ID="txtsqlexec" runat="server" Width="325px" Text="updateTableByParm"></asp:TextBox>
30 </td>
31 </tr>
32 <tr>
33 <td>
34 <asp:Button ID="btnExec" runat ="server" Text ="执行" OnClick="btnExec_Click" />
35 </td>
36 </tr>
37 </table>
38 </div>
39 </form>
40 </body>
41 </html>
42
1 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="ExcuteProcParm.aspx.cs" Inherits="ExcuteProcParm" %>
2
3 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
4 <html xmlns="http://www.w3.org/1999/xhtml">
5 <head runat="server">
6 <title>ExecuteProcParm</title>
7 </head>
8 <body>
9 <form id="form1" runat="server">
10 <div>
11 <table style=" 396px; height: 159px">
12 <tr>
13 <td>
14 参数名:<asp:TextBox ID="txtparm" runat="server" Width="256px" Text="id"></asp:TextBox>
15 </td>
16 </tr>
17 <tr>
18 <td>
19 参数值:<asp:TextBox ID="txtvalue" runat="server" Width="252px" Text="1"></asp:TextBox>
20 </td>
21 </tr>
22 <tr>
23 <td>
24 要执行的存储过程名:
25 </td>
26 </tr>
27 <tr>
28 <td>
29 <asp:TextBox ID="txtsqlexec" runat="server" Width="325px" Text="updateTableByParm"></asp:TextBox>
30 </td>
31 </tr>
32 <tr>
33 <td>
34 <asp:Button ID="btnExec" runat ="server" Text ="执行" OnClick="btnExec_Click" />
35 </td>
36 </tr>
37 </table>
38 </div>
39 </form>
40 </body>
41 </html>
42
ExcuteProcParm.aspx.cs(示例)
1 using System;
2 using System.Data;
3 using System.Configuration;
4 using System.Collections;
5 using System.Web;
6 using System.Web.Security;
7 using System.Web.UI;
8 using System.Web.UI.WebControls;
9 using System.Web.UI.WebControls.WebParts;
10 using System.Web.UI.HtmlControls;
11 using System.Data.SqlClient;
12
13 public partial class ExcuteProcParm : System.Web.UI.Page
14 {
15 protected void Page_Load(object sender, EventArgs e)
16 {
17
18 }
19 protected void btnExec_Click(object sender, EventArgs e)
20 {
21 //初始化参数
22 SqlParameter myParm = new SqlParameter();
23
24 //获取参数的名字
25 myParm.ParameterName = txtparm.Text;
26
27 //设置变量的类型和长度
28 myParm.SqlDbType = SqlDbType.NVarChar;
29 myParm.Size = 20;
30
31 //获取参数值
32 myParm.Value = txtvalue.Text;
33 //获取要执行的存储过程名
34 string sqlexec = txtsqlexec.Text;
35
36 using (SqlConnection conn = new SqlConnection (SqlHelper .ConnectionStringLocalTransaction ))
37 {
38 //打开连接
39 conn.Open();
40
41 //调用执行方法
42 SqlHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, sqlexec, myParm);
43
44 Response.Write("<font color='red'>操作成功。</Font>");
45 }
46 }
47 }
48
1 using System;
2 using System.Data;
3 using System.Configuration;
4 using System.Collections;
5 using System.Web;
6 using System.Web.Security;
7 using System.Web.UI;
8 using System.Web.UI.WebControls;
9 using System.Web.UI.WebControls.WebParts;
10 using System.Web.UI.HtmlControls;
11 using System.Data.SqlClient;
12
13 public partial class ExcuteProcParm : System.Web.UI.Page
14 {
15 protected void Page_Load(object sender, EventArgs e)
16 {
17
18 }
19 protected void btnExec_Click(object sender, EventArgs e)
20 {
21 //初始化参数
22 SqlParameter myParm = new SqlParameter();
23
24 //获取参数的名字
25 myParm.ParameterName = txtparm.Text;
26
27 //设置变量的类型和长度
28 myParm.SqlDbType = SqlDbType.NVarChar;
29 myParm.Size = 20;
30
31 //获取参数值
32 myParm.Value = txtvalue.Text;
33 //获取要执行的存储过程名
34 string sqlexec = txtsqlexec.Text;
35
36 using (SqlConnection conn = new SqlConnection (SqlHelper .ConnectionStringLocalTransaction ))
37 {
38 //打开连接
39 conn.Open();
40
41 //调用执行方法
42 SqlHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, sqlexec, myParm);
43
44 Response.Write("<font color='red'>操作成功。</Font>");
45 }
46 }
47 }
48