注册:
protected void btnlogin_Click(object sender, EventArgs e)
{
string username = txtusername.Text.Trim();
string password = txtpassword.Text.Trim();
string email = txtemail.Text.Trim();
using (SqlConnection conn = new SqlConnection(MyTestconstr))
{
conn.Open();
using (SqlCommand cmd = conn.CreateCommand())
{
string sp_name = "usp_regiter2";
cmd.CommandText = sp_name;
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter prm1 = new SqlParameter("@username", username);
SqlParameter prm2 = new SqlParameter("@password", password);
SqlParameter prm3 = new SqlParameter ("@email",email );
cmd.Parameters.Add(prm1);
cmd.Parameters.Add(prm2);
cmd.Parameters.Add(prm3);
int r = cmd.ExecuteNonQuery();
Label1.Text = r.ToString();
}
}
}
删:
protected void Button2_Click(object sender, EventArgs e)
{
using (SqlConnection conn = new SqlConnection(MyTestconstr))
{
conn.Open ();
using (SqlCommand cmd = conn.CreateCommand())
{
string sp_name = "usp_student_delete";
cmd.CommandText = sp_name;
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter prm = new SqlParameter("@sid", 3);
cmd.Parameters.Add(prm);
int r=cmd.ExecuteNonQuery();
if (r > 0)
{
Label1.Text = "删除成功!";
}
else
{
Label1.Text = "删除失败!";
}
}
}
}
改:
protected void Button3_Click(object sender, EventArgs e)
{
string schoolsconstr = ConfigurationManager.ConnectionStrings["schoolsconstr"].ConnectionString;
using (SqlConnection conn = new SqlConnection(schoolsconstr))
{
conn.Open();
using (SqlCommand cmd = conn.CreateCommand())
{
string sp_name = "usp_Class_update";
cmd.CommandText = sp_name;
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter prm1 = new SqlParameter( "@clsname",txtusername.Text );
SqlParameter prm2 = new SqlParameter( "@disc ",txtpassword .Text );
SqlParameter prm3 = new SqlParameter("@clsid ", txtdelete .Text );
cmd.Parameters.Add(prm1);
cmd.Parameters.Add(prm2);
cmd.Parameters.Add(prm3);
int r = cmd.ExecuteNonQuery();
if (r > 0)
{
Label1.Text = "更新成功!";
}
else
{
Label1.Text = "更新失败!";
}
}
}
登陆:方法一
protected void btnlogin_Click(object sender, EventArgs e)
{
string username = txtusername.Text.Trim();
string password = txtpassword.Text.Trim();
string MyTestconstr= ConfigurationManager.ConnectionStrings["MyTestconstr"].ConnectionString;
using (SqlConnection conn=new SqlConnection (MyTestconstr))
{
conn.Open();
using(SqlCommand cmd=conn.CreateCommand ())
{
string sp_name="usp_login";
cmd.CommandText = sp_name;
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter prm1 = new SqlParameter("@uname", username);
SqlParameter prm2 = new SqlParameter("@password",password );
SqlParameter prm3 = new SqlParameter("@result",System.Data .SqlDbType .Bit );
prm3.Direction = ParameterDirection.Output;-------------------注意点
cmd.Parameters .Add (prm1 );
cmd.Parameters .Add (prm2 );
cmd.Parameters .Add (prm3 );
int r = cmd.ExecuteNonQuery();
bool b=Convert .ToBoolean (prm3.Value );
if (b)
{
Label1.Text ="登陆成功";
}
else
{
Label1 .Text ="登陆失败";
}
}
}
方法二:
protected void btnlogin_Click(object sender, EventArgs e)
{
string username = txtusername.Text.Trim();
string password = txtpassword.Text.Trim();
string MyTestconstr= ConfigurationManager.ConnectionStrings["MyTestconstr"].ConnectionString;
using (SqlConnection conn=new SqlConnection (MyTestconstr))
{
conn.Open();
using(SqlCommand cmd=conn.CreateCommand ())
{
string sp_name = "usp_chkLogin";
cmd.CommandText = sp_name;
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter prm1 = new SqlParameter("@username", username);
SqlParameter prm2 = new SqlParameter("@password",password );
cmd.Parameters .Add (prm1 );
cmd.Parameters .Add (prm2 );
object obj = cmd.ExecuteScalar();
int b = Convert.ToInt32(obj);
if (b>0)
{
Label1.Text ="登陆成功";
}
else
{
Label1 .Text ="登陆失败";
}
}
}