Default.aspx
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head id="Head1" runat="server"> <title>无标题页</title> </head> <body style="font-size: 12px"> <form id="form1" runat="server"> <div> <table style="border-right: #000099 thin groove; border-top: #000099 thin groove; border-left: #000099 thin groove; width: 286px; border-bottom: #000099 thin groove; height: 52px"> <tr> <td colspan="2" style="text-align: center"> <strong><span style="font-size: 12pt; color: #000099; text-decoration: underline">修改会员基本信息</span></strong></td> </tr> <tr> <td style="width: 121px"> 会员编号:</td> <td style="width: 275px"> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></td> </tr> <tr> <td style="width: 121px"> 会员姓名:</td> <td style="width: 275px"> <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox></td> </tr> <tr> <td style="width: 121px"> 身份证号:</td> <td style="width: 275px"> <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox></td> </tr> <tr> <td style="width: 121px"> 联系电话:</td> <td style="width: 275px"> <asp:TextBox ID="TextBox4" runat="server"></asp:TextBox></td> </tr> <tr> <td style="width: 121px"> </td> <td align="center" style="width: 275px"> <asp:Button ID="Button1" runat="server" OnClick="Button1_Click1" Text="保 存" /></td> </tr> </table> </div> </form> </body> </html>
Default.aspx.cs
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
using System; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; using System.Data.SqlClient; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click1(object sender, EventArgs e) { try { SqlConnection con = new SqlConnection("Server=localhost;database=db2_Tome2;Uid=sa;Pwd=123");//创建数据库连接 con.Open();//打开数据库连接 SqlCommand cmd = new SqlCommand("procUpdateEmployee", con);//调用存储过程 cmd.CommandType = CommandType.StoredProcedure;//设定数据操作类型为存储过程 SqlParameter[] prams = {//设定参数 new SqlParameter("@员工编号", SqlDbType.VarChar, 50,TextBox1.Text), new SqlParameter("@员工姓名", SqlDbType.VarChar, 50), new SqlParameter("@身份证号", SqlDbType.VarChar, 50), new SqlParameter("@联系电话", SqlDbType.VarChar, 50) }; prams[0].Value = TextBox1.Text; prams[1].Value = TextBox2.Text; prams[2].Value = TextBox3.Text; prams[3].Value = TextBox4.Text; // 依次把参数传入命令文本 foreach (SqlParameter parameter in prams) { cmd.Parameters.Add(parameter); } cmd.ExecuteNonQuery();//执行修改操作 Response.Write("修改成功!"); } catch (Exception ex) { Response.Write(ex.Message); } } }