update.aspx
<%
@ Page language
=
"
C#
"
Codebehind
=
"
update.aspx.cs
"
AutoEventWireup
=
"
false
"
Inherits
=
"
DotNetTest.database.update
"
%>
<! DOCTYPE HTML PUBLIC " -//W3C//DTD HTML 4.0 Transitional//EN " >
< HTML >
< HEAD >
< title > update </ title >
< meta name = " GENERATOR " Content = " Microsoft Visual Studio 7.0 " >
< meta name = " CODE_LANGUAGE " Content = " C# " >
< meta name = " vs_defaultClientScript " content = " JavaScript " >
< meta name = " vs_targetSchema " content = " http://schemas.microsoft.com/intellisense/ie5 " >
</ HEAD >
< body >
< form id = " update " method = " post " runat = " server " >
< P >< FONT face = " 宋体 " color = " #ff6600 " >------------ 帐号注册 ------------</ FONT ></ P >
< P >< FONT style = " FONT-STYLE: italic " face = " 宋体 " color = " #ff6600 " > 必填: </ FONT ></ P >
< P >< FONT face = " 宋体 " > 帐号:
< asp:TextBox id = " TB_Account " runat = " server " ></ asp:TextBox >
< asp:Label id = " Lbl_Msg " style = " Z-INDEX: 101; LEFT: 305px; POSITION: absolute; TOP: 94px " runat = " server " Width = " 177px " Height = " 59px " BackColor = " White " ForeColor = " Red " ></ asp:Label ></ P >
</ FONT >
< P >< FONT face = " 宋体 " > 密码:
< asp:TextBox id = " TB_Password1 " runat = " server " ></ asp:TextBox ></ FONT ></ P >
< P >< FONT face = " 宋体 " > 确认密码:
< asp:TextBox id = " TB_Password2 " runat = " server " ></ asp:TextBox ></ FONT ></ P >
< P >< FONT face = " 宋体 " >---------
< asp:Button id = " B_OKGOPinjie " runat = " server " Text = " OK,GO拼接字符串 " Width = " 160px " ></ asp:Button >
< asp:LinkButton id = " LB_SeeResult " style = " Z-INDEX: 102; LEFT: 312px; POSITION: absolute; TOP: 203px " runat = " server " Width = " 116px " Height = " 23px " Visible = " False " > 查看数据库内容 </ asp:LinkButton ></ FONT ></ P >
< P >< FONT face = " 宋体 " >---------
< asp:Button id = " B_OKGOParm " runat = " server " Text = " OK,GO使用参数 " Width = " 161px " ></ asp:Button ></ FONT ></ P >
< P >< FONT face = " 宋体 " >---------
< asp:Button id = " B_OKGOStore " runat = " server " Text = " OK,GO使用存储过程 " Width = " 161px " ></ asp:Button ></ P >
</ FONT >
< P >< FONT style = " FONT-STYLE: italic " face = " 宋体 " color = " #ff6600 " > 选填: </ P >
</ FONT >
< P >< FONT face = " 宋体 " > 昵称:
< asp:TextBox id = " TB_VirtualName " runat = " server " ></ asp:TextBox ></ FONT ></ P >
< P >< FONT face = " 宋体 " > 性别:
< asp:RadioButtonList id = " RBL_Sex " runat = " server " RepeatDirection = " Horizontal " RepeatLayout = " Flow " >
< asp:ListItem Value = " M " Selected = " True " > 男 </ asp:ListItem >
< asp:ListItem Value = " F " > 女 </ asp:ListItem >
</ asp:RadioButtonList ></ FONT >< FONT face = " 宋体 " ></ P >
</ FONT >
</ form >
</ body >
</ HTML >
<! DOCTYPE HTML PUBLIC " -//W3C//DTD HTML 4.0 Transitional//EN " >
< HTML >
< HEAD >
< title > update </ title >
< meta name = " GENERATOR " Content = " Microsoft Visual Studio 7.0 " >
< meta name = " CODE_LANGUAGE " Content = " C# " >
< meta name = " vs_defaultClientScript " content = " JavaScript " >
< meta name = " vs_targetSchema " content = " http://schemas.microsoft.com/intellisense/ie5 " >
</ HEAD >
< body >
< form id = " update " method = " post " runat = " server " >
< P >< FONT face = " 宋体 " color = " #ff6600 " >------------ 帐号注册 ------------</ FONT ></ P >
< P >< FONT style = " FONT-STYLE: italic " face = " 宋体 " color = " #ff6600 " > 必填: </ FONT ></ P >
< P >< FONT face = " 宋体 " > 帐号:
< asp:TextBox id = " TB_Account " runat = " server " ></ asp:TextBox >
< asp:Label id = " Lbl_Msg " style = " Z-INDEX: 101; LEFT: 305px; POSITION: absolute; TOP: 94px " runat = " server " Width = " 177px " Height = " 59px " BackColor = " White " ForeColor = " Red " ></ asp:Label ></ P >
</ FONT >
< P >< FONT face = " 宋体 " > 密码:
< asp:TextBox id = " TB_Password1 " runat = " server " ></ asp:TextBox ></ FONT ></ P >
< P >< FONT face = " 宋体 " > 确认密码:
< asp:TextBox id = " TB_Password2 " runat = " server " ></ asp:TextBox ></ FONT ></ P >
< P >< FONT face = " 宋体 " >---------
< asp:Button id = " B_OKGOPinjie " runat = " server " Text = " OK,GO拼接字符串 " Width = " 160px " ></ asp:Button >
< asp:LinkButton id = " LB_SeeResult " style = " Z-INDEX: 102; LEFT: 312px; POSITION: absolute; TOP: 203px " runat = " server " Width = " 116px " Height = " 23px " Visible = " False " > 查看数据库内容 </ asp:LinkButton ></ FONT ></ P >
< P >< FONT face = " 宋体 " >---------
< asp:Button id = " B_OKGOParm " runat = " server " Text = " OK,GO使用参数 " Width = " 161px " ></ asp:Button ></ FONT ></ P >
< P >< FONT face = " 宋体 " >---------
< asp:Button id = " B_OKGOStore " runat = " server " Text = " OK,GO使用存储过程 " Width = " 161px " ></ asp:Button ></ P >
</ FONT >
< P >< FONT style = " FONT-STYLE: italic " face = " 宋体 " color = " #ff6600 " > 选填: </ P >
</ FONT >
< P >< FONT face = " 宋体 " > 昵称:
< asp:TextBox id = " TB_VirtualName " runat = " server " ></ asp:TextBox ></ FONT ></ P >
< P >< FONT face = " 宋体 " > 性别:
< asp:RadioButtonList id = " RBL_Sex " runat = " server " RepeatDirection = " Horizontal " RepeatLayout = " Flow " >
< asp:ListItem Value = " M " Selected = " True " > 男 </ asp:ListItem >
< asp:ListItem Value = " F " > 女 </ asp:ListItem >
</ asp:RadioButtonList ></ FONT >< FONT face = " 宋体 " ></ P >
</ FONT >
</ form >
</ body >
</ HTML >
update.aspx.cs
using
System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Configuration;
namespace DotNetTest.database
... {
/**//// <summary>
/// update 的摘要说明。
/// </summary>
public class update : System.Web.UI.Page
...{
protected System.Web.UI.WebControls.TextBox TB_Account;
protected System.Web.UI.WebControls.TextBox TB_Password1;
protected System.Web.UI.WebControls.TextBox TB_Password2;
protected System.Web.UI.WebControls.TextBox TB_VirtualName;
protected System.Web.UI.WebControls.Button B_OKGOPinjie;
protected System.Web.UI.WebControls.Button B_OKGOParm;
protected System.Web.UI.WebControls.Button B_OKGOStore;
protected System.Web.UI.WebControls.Label Lbl_Msg;
protected System.Web.UI.WebControls.LinkButton LB_SeeResult;
protected System.Web.UI.WebControls.RadioButtonList RBL_Sex;
private bool CheckInfo()
...{
if(this.TB_Account.Text.Trim()=="")
...{
Alert("学号不完整");
return false;
}
else if(this.TB_Password1.Text.Trim()==""||this.TB_Password2.Text.Trim()=="")
...{
Alert("密码不完整");
return false;
}
else if(this.TB_Password1.Text.Trim()!=this.TB_Password2.Text.Trim())
...{
Alert("密码确认失败!");
return false;
}
return true;
}
private void Alert(string str)
...{
Lbl_Msg.Text=str;
Lbl_Msg.BackColor=System.Drawing.Color.DimGray;
LB_SeeResult.Visible=true;
}
private bool IsOKAccount()
...{
string usrAccount=this.TB_Account.Text.Trim();
try
...{
//config the database
string strConn=ConfigurationSettings.AppSettings["MSSQLConnStr_FSLink"];
SqlConnection sqlConn=new SqlConnection();
sqlConn.ConnectionString=strConn;
//the SQL string
string sqlCount="SELECT COUNT(*) FROM FSL_USER WHERE USER_ID=@userID";
//create the command
SqlCommand cmd=new SqlCommand(sqlCount,sqlConn);
//add parameters
cmd.Parameters.Add(new SqlParameter("@userID",usrAccount));
//open the database
sqlConn.Open();
//save the affected result
string aff=cmd.ExecuteScalar().ToString();
//close the database
sqlConn.Close();
if(Int32.Parse(aff)!=0)
...{
Alert("帐号已经存在");
return false;
}
return true;
}
catch(Exception ex)
...{
Alert(ex.Message);
return false;
}
}
private void Page_Load(object sender, System.EventArgs e)
...{
// 在此处放置用户代码以初始化页面
}
Web Form Designer generated code#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
...{
//
// CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/**//// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
...{
this.B_OKGOPinjie.Click += new System.EventHandler(this.B_OKGOPinjie_Click);
this.LB_SeeResult.Click += new System.EventHandler(this.LB_SeeResult_Click);
this.B_OKGOParm.Click += new System.EventHandler(this.B_OKGOParm_Click);
this.B_OKGOStore.Click += new System.EventHandler(this.B_OKGOStore_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void B_OKGOPinjie_Click(object sender, System.EventArgs e)
...{
if(!IsOKAccount())
...{
return;
}
if(this.CheckInfo())
...{
//get the acquired value
string usrAccount=this.TB_Account.Text.Trim();
string usrPassword=this.TB_Password1.Text.Trim();
string usrVirtualName=this.TB_VirtualName.Text.Trim();
string usrSex=this.RBL_Sex.SelectedItem.Value.Trim();
//operate the database
try
...{
//config the database
string strConn=ConfigurationSettings.AppSettings["MSSQLConnStr_FSLink"];
SqlConnection sqlConn=new SqlConnection();
sqlConn.ConnectionString=strConn;
//the SQL string
string sqlInsert="INSERT INTO FSL_USER(USER_ID,USER_NAME,USER_SEX,USER_PASSWORD)"+
" VALUES('"+usrAccount+"','"+usrVirtualName+"','"+usrSex+"','"+usrPassword+"')";
//create the command
SqlCommand cmd=new SqlCommand(sqlInsert,sqlConn);
//open the database
sqlConn.Open();
//save the affected result
int aff=cmd.ExecuteNonQuery();
//close the reader and the database
sqlConn.Close();
Alert("使用拼接字符串:数据添加成功"+aff+"条!");
}
catch(Exception ex)
...{
Alert(ex.Message);
}
}
}
private void B_OKGOParm_Click(object sender, System.EventArgs e)
...{
if(this.CheckInfo())
...{
if(!IsOKAccount())
...{
return;
}
//get the acquired value
string usrAccount=this.TB_Account.Text.Trim();
string usrPassword=this.TB_Password1.Text.Trim();
string usrVirtualName=this.TB_VirtualName.Text.Trim();
string usrSex=this.RBL_Sex.SelectedItem.Value.Trim();
//operate the database
try
...{
//config the database
string strConn=ConfigurationSettings.AppSettings["MSSQLConnStr_FSLink"];
SqlConnection sqlConn=new SqlConnection();
sqlConn.ConnectionString=strConn;
//the SQL string
string sqlInsert="INSERT INTO FSL_USER(USER_ID,USER_NAME,USER_SEX,USER_PASSWORD)"+
" VALUES(@userID,@userName,@userSex,@userPassword)";
//create the command
SqlCommand cmd=new SqlCommand(sqlInsert,sqlConn);
//add parameters
cmd.Parameters.Add(new SqlParameter("@userID",usrAccount));
cmd.Parameters.Add(new SqlParameter("@userName",usrVirtualName));
cmd.Parameters.Add(new SqlParameter("@userSex",usrSex));
cmd.Parameters.Add(new SqlParameter("@userPassword",usrPassword));
//open the database
sqlConn.Open();
//save the affected result
int aff=cmd.ExecuteNonQuery();
//close the reader and the database
sqlConn.Close();
Alert("使用参数:数据添加成功"+aff+"条!");
}
catch(Exception ex)
...{
Alert(ex.Message);
}
}
}
private void B_OKGOStore_Click(object sender, System.EventArgs e)
...{
if(!IsOKAccount())
...{
return;
}
if(this.CheckInfo())
...{
//get the acquired value
string usrAccount=this.TB_Account.Text.Trim();
string usrPassword=this.TB_Password1.Text.Trim();
string usrVirtualName=this.TB_VirtualName.Text.Trim();
string usrSex=this.RBL_Sex.SelectedItem.Value.Trim();
//operate the database
try
...{
//config the database
string strConn=ConfigurationSettings.AppSettings["MSSQLConnStr_FSLink"];
SqlConnection sqlConn=new SqlConnection();
sqlConn.ConnectionString=strConn;
//create the command
SqlCommand cmd=new SqlCommand("InsertUser",sqlConn);
cmd.CommandType=CommandType.StoredProcedure;
//add parameters
cmd.Parameters.Add(new SqlParameter("@userID",usrAccount));
cmd.Parameters.Add(new SqlParameter("@userName",usrVirtualName));
cmd.Parameters.Add(new SqlParameter("@userSex",usrSex));
cmd.Parameters.Add(new SqlParameter("@userPassword",usrPassword));
//open the database
sqlConn.Open();
//save the affected result
int aff=cmd.ExecuteNonQuery();
//close the reader and the database
sqlConn.Close();
Alert("使用存储过程:数据添加成功"+aff+"条!");
}
catch(Exception ex)
...{
Alert(ex.Message);
}
}
}
private void LB_SeeResult_Click(object sender, System.EventArgs e)
...{
Server.Transfer("select_adapter.aspx");
}
}
}
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Configuration;
namespace DotNetTest.database
... {
/**//// <summary>
/// update 的摘要说明。
/// </summary>
public class update : System.Web.UI.Page
...{
protected System.Web.UI.WebControls.TextBox TB_Account;
protected System.Web.UI.WebControls.TextBox TB_Password1;
protected System.Web.UI.WebControls.TextBox TB_Password2;
protected System.Web.UI.WebControls.TextBox TB_VirtualName;
protected System.Web.UI.WebControls.Button B_OKGOPinjie;
protected System.Web.UI.WebControls.Button B_OKGOParm;
protected System.Web.UI.WebControls.Button B_OKGOStore;
protected System.Web.UI.WebControls.Label Lbl_Msg;
protected System.Web.UI.WebControls.LinkButton LB_SeeResult;
protected System.Web.UI.WebControls.RadioButtonList RBL_Sex;
private bool CheckInfo()
...{
if(this.TB_Account.Text.Trim()=="")
...{
Alert("学号不完整");
return false;
}
else if(this.TB_Password1.Text.Trim()==""||this.TB_Password2.Text.Trim()=="")
...{
Alert("密码不完整");
return false;
}
else if(this.TB_Password1.Text.Trim()!=this.TB_Password2.Text.Trim())
...{
Alert("密码确认失败!");
return false;
}
return true;
}
private void Alert(string str)
...{
Lbl_Msg.Text=str;
Lbl_Msg.BackColor=System.Drawing.Color.DimGray;
LB_SeeResult.Visible=true;
}
private bool IsOKAccount()
...{
string usrAccount=this.TB_Account.Text.Trim();
try
...{
//config the database
string strConn=ConfigurationSettings.AppSettings["MSSQLConnStr_FSLink"];
SqlConnection sqlConn=new SqlConnection();
sqlConn.ConnectionString=strConn;
//the SQL string
string sqlCount="SELECT COUNT(*) FROM FSL_USER WHERE USER_ID=@userID";
//create the command
SqlCommand cmd=new SqlCommand(sqlCount,sqlConn);
//add parameters
cmd.Parameters.Add(new SqlParameter("@userID",usrAccount));
//open the database
sqlConn.Open();
//save the affected result
string aff=cmd.ExecuteScalar().ToString();
//close the database
sqlConn.Close();
if(Int32.Parse(aff)!=0)
...{
Alert("帐号已经存在");
return false;
}
return true;
}
catch(Exception ex)
...{
Alert(ex.Message);
return false;
}
}
private void Page_Load(object sender, System.EventArgs e)
...{
// 在此处放置用户代码以初始化页面
}
Web Form Designer generated code#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
...{
//
// CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/**//// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
...{
this.B_OKGOPinjie.Click += new System.EventHandler(this.B_OKGOPinjie_Click);
this.LB_SeeResult.Click += new System.EventHandler(this.LB_SeeResult_Click);
this.B_OKGOParm.Click += new System.EventHandler(this.B_OKGOParm_Click);
this.B_OKGOStore.Click += new System.EventHandler(this.B_OKGOStore_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void B_OKGOPinjie_Click(object sender, System.EventArgs e)
...{
if(!IsOKAccount())
...{
return;
}
if(this.CheckInfo())
...{
//get the acquired value
string usrAccount=this.TB_Account.Text.Trim();
string usrPassword=this.TB_Password1.Text.Trim();
string usrVirtualName=this.TB_VirtualName.Text.Trim();
string usrSex=this.RBL_Sex.SelectedItem.Value.Trim();
//operate the database
try
...{
//config the database
string strConn=ConfigurationSettings.AppSettings["MSSQLConnStr_FSLink"];
SqlConnection sqlConn=new SqlConnection();
sqlConn.ConnectionString=strConn;
//the SQL string
string sqlInsert="INSERT INTO FSL_USER(USER_ID,USER_NAME,USER_SEX,USER_PASSWORD)"+
" VALUES('"+usrAccount+"','"+usrVirtualName+"','"+usrSex+"','"+usrPassword+"')";
//create the command
SqlCommand cmd=new SqlCommand(sqlInsert,sqlConn);
//open the database
sqlConn.Open();
//save the affected result
int aff=cmd.ExecuteNonQuery();
//close the reader and the database
sqlConn.Close();
Alert("使用拼接字符串:数据添加成功"+aff+"条!");
}
catch(Exception ex)
...{
Alert(ex.Message);
}
}
}
private void B_OKGOParm_Click(object sender, System.EventArgs e)
...{
if(this.CheckInfo())
...{
if(!IsOKAccount())
...{
return;
}
//get the acquired value
string usrAccount=this.TB_Account.Text.Trim();
string usrPassword=this.TB_Password1.Text.Trim();
string usrVirtualName=this.TB_VirtualName.Text.Trim();
string usrSex=this.RBL_Sex.SelectedItem.Value.Trim();
//operate the database
try
...{
//config the database
string strConn=ConfigurationSettings.AppSettings["MSSQLConnStr_FSLink"];
SqlConnection sqlConn=new SqlConnection();
sqlConn.ConnectionString=strConn;
//the SQL string
string sqlInsert="INSERT INTO FSL_USER(USER_ID,USER_NAME,USER_SEX,USER_PASSWORD)"+
" VALUES(@userID,@userName,@userSex,@userPassword)";
//create the command
SqlCommand cmd=new SqlCommand(sqlInsert,sqlConn);
//add parameters
cmd.Parameters.Add(new SqlParameter("@userID",usrAccount));
cmd.Parameters.Add(new SqlParameter("@userName",usrVirtualName));
cmd.Parameters.Add(new SqlParameter("@userSex",usrSex));
cmd.Parameters.Add(new SqlParameter("@userPassword",usrPassword));
//open the database
sqlConn.Open();
//save the affected result
int aff=cmd.ExecuteNonQuery();
//close the reader and the database
sqlConn.Close();
Alert("使用参数:数据添加成功"+aff+"条!");
}
catch(Exception ex)
...{
Alert(ex.Message);
}
}
}
private void B_OKGOStore_Click(object sender, System.EventArgs e)
...{
if(!IsOKAccount())
...{
return;
}
if(this.CheckInfo())
...{
//get the acquired value
string usrAccount=this.TB_Account.Text.Trim();
string usrPassword=this.TB_Password1.Text.Trim();
string usrVirtualName=this.TB_VirtualName.Text.Trim();
string usrSex=this.RBL_Sex.SelectedItem.Value.Trim();
//operate the database
try
...{
//config the database
string strConn=ConfigurationSettings.AppSettings["MSSQLConnStr_FSLink"];
SqlConnection sqlConn=new SqlConnection();
sqlConn.ConnectionString=strConn;
//create the command
SqlCommand cmd=new SqlCommand("InsertUser",sqlConn);
cmd.CommandType=CommandType.StoredProcedure;
//add parameters
cmd.Parameters.Add(new SqlParameter("@userID",usrAccount));
cmd.Parameters.Add(new SqlParameter("@userName",usrVirtualName));
cmd.Parameters.Add(new SqlParameter("@userSex",usrSex));
cmd.Parameters.Add(new SqlParameter("@userPassword",usrPassword));
//open the database
sqlConn.Open();
//save the affected result
int aff=cmd.ExecuteNonQuery();
//close the reader and the database
sqlConn.Close();
Alert("使用存储过程:数据添加成功"+aff+"条!");
}
catch(Exception ex)
...{
Alert(ex.Message);
}
}
}
private void LB_SeeResult_Click(object sender, System.EventArgs e)
...{
Server.Transfer("select_adapter.aspx");
}
}
}