CS0103: 当前上下文中不存在名称“user_name”
它对user_id没有出错.为什么这里会出错呢?下面是代码:
<%@ Import Namespace="System.Data"%>
<%@ Import Namespace="System.Data.SqlClient"%>
<%@ Page Language="C#" Debug="true"%>
<%@ Import Namespace="System.Web.Mail" %>
<script language="C#" runat=server>
void Button1_click(object sender,EventArgs E)
{
SqlConnection conn=new SqlConnection("Persist Security Info=false;database=datac;server=.;uid=sa;pwd=sql");
String insertCmd="insert into users(user_id,user_name,user_password,email) values
(@user_id,@user_name,@user_pwd,@email)";
SqlCommand istCmd=new SqlCommand(insertCmd,conn);
istCmd.Parameters.Add("@user_id",SqlDbType.VarChar,50).Value=user_id.Text;
istCmd.Parameters.Add("@user_name",SqlDbType.VarChar,20).Value=user_name.Text;
istCmd.Parameters.Add("@user_password",SqlDbType.VarChar,20).Value=user_password.Text;
istCmd.Parameters.Add("@email",SqlDbType.VarChar,50).Value=email.Text;
try
{
conn.Open();
istCmd.ExecuteNonQuery();
conn.Close();
MailMessage myMail=new MailMessage();
myMail.BodyFormat=MailFormat.Html;
myMail.Subject="学生成绩系统注册";
myMail.From="[email=ren1986q@swu.]ren1986q@swu.[/email]";
myMail.To=email.Text;
myMail.Body="您已成功注册!<br>您的账号是:"+user_id.Text+"<br>您的密码是:"+user_password.Text+"<p/>";
SmtpMail.Send(myMail);
Response.Redirect("index.htm");
}
catch(System.Data.SqlClient.SqlException e)
{
if(e.Number==2627)
{
RequiredFieldValidator2.ErrorMessage="用户ID已经存在,请重新输入!";
RequiredFieldValidator2.IsValid=false;
}
Response.Write(e.ToString());
}
}
</script>
<html>
<head>
<title>学生注册</title>
<meta http-equiv="Content-Type" c>
</head>
<body bgcolor="#CACACA" text="green" link="#ffff00" vlin="#ffff00" alink="#00ff00">
<center><h1><font color="green" >学生成绩管理系统学生注册</font></h1></center>
<form method="post" id="form" runat="server">
<table width="400" border="0" align="center">
<tr>
<td colspan="2">
<div align="center"><font size="4" color="green"><<font face="宋体">您的个人资料</font>><font
size="4"> <font color="red" >*</font></font><font class="font9ptblack" face="宋体
" color="green"><font size="4">表示必填</font></font></div>
</td>
</tr>
<tr>
<td valign="top" align="right">
<font color="red">*</font><font color="green"><font face="宋体">姓名</font>:</font>
</td>
<td>
<asp:RequiredFieldValidator id="RequiredFieldValidator1"
C Display="Dynamic"
ErrorMessage="请输入姓名!" runat="server"/>
</td>
</tr>
<tr>
<td valign="top" align="right">
<font color="red">*</font><font color="green">用户ID:</font>
</td>
<td>
<asp:TextBox id="user_id" columns="20" maxlength="20" runat="server"/><br>
<asp:RequiredFieldValidator id="RequiredFieldValidator2"
C Display="Dynamic"
ErrorMessage="请输入用户ID!" runat="server"/>
</td>
</tr>
<tr>
<td valign="top" align="right">
<font color="red">*</font><font color="green" ><font face="宋体">密码</font>:</font>
</td>
<td>
<asp:TextBox id="user_password" TextMode="Password" columns="20" maxlengh="20" runat="server"/><br>
<asp:RequiredFieldValidator id="RequiredFieldValidator3"
C Display="Dynamic"
ErrorMessage="请输入密码!" runat="server" />
</td>
</tr>
<tr>
<td valign="top" align="right">
<font color="red">*</font><font color="green" ><font face="宋体">确认密码</font>:</font>
</td>
<td>
<asp:TextBox id="user_password1" TextMode="Password" columns="20" maxlengh="20" runat="server"/><BR/>
<asp:RequiredFieldValidator id="RequiredFieldValidator4"
C Display="Dynamic"
ErrorMessage="请确认密码!" runat="server" />
<asp:CompareValidator id="CompareValidator1"
C C
Type="String"
Operator="Equal"
Display="Dynamic"
ErrorMessage="两次输入密码不一致,请重新输入!" runat="server"/>
</td>
</tr>
<tr>
<td valign="top" align="right">
<font color="red">*</font><font color="green">E-mail:</font>
</td>
<td>
<asp:TextBox id="email" columns="30" maslength="50" runat="server"/><BR/>
<asp:RequiredFieldValidator id="RequiredFieldValidator6"
C Display="Dynamic"
ErrorMessage="请输入e-mail!哈哈" runat="server"/>
<asp:RegularExpressionValidator id="RegularExpressionValidator2"
C Display="Dynamic"
Validati
ErrorMessage="E-mail格式输入错误!" runat="server"/>
</td>
</tr>
<tr align="center">
<td colspan=2>
<asp:Button id="Button1" Text="注册" runat="server" />
</td>
</tr>
</table></form>
</body>
</html>