ASP.NET登録と登録コード
1732 ワード
ログインバックグラウンドコード
バックグラウンドコードの登録
protected void LoginSubmit_Click(object sender, EventArgs e)
{
string uname = name.Text.Trim();
string pwd = password.Text.Trim();
SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ToString());
string sql = string.Format("select count(*) from userinfo where username='{0}' and password='{1}'", uname, pwd);
SqlCommand command = new SqlCommand(sql, connection);
connection.Open();
int a = (int)command.ExecuteScalar();
connection.Close();
if (a > 0) //
{
Session["admin_user"] = uname;
}
else //
{
Response.Write(" alert(' , ') ");
}
}
バックグラウンドコードの登録
protected void Registersubmit_Click(object sender, EventArgs e)
{
string a1 = name.Text.Trim();
string a2 = password.Text.Trim();
string a3 = DateTime.Now.ToString();
SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ToString());
string sql = string.Format("insert into register values( '{0}','{1}','{2}')", a1, a2, a3);
SqlCommand command = new SqlCommand(sql, connection);
connection.Open();
int count = (int)command.ExecuteNonQuery();
connection.Close();
if (count > 0)
{
Response.Write("alert(' ') ");
}
else
{
Response.Write("alert(' , ') ");
}
}