有关ASP.NET的一段代码看不懂请高手解释下,最好是每句都解释!谢谢啊
#endregionprivatevoidlogbut_Click(objectsender,System.EventArgse){stringconnectionStr...
#endregion
private void logbut_Click(object sender, System.EventArgs e)
{
string connectionString=ConfigurationSettings.AppSettings["connectstr"].ToString();
SqlConnection sampleConnection = new SqlConnection(connectionString);
sampleConnection.ConnectionString = connectionString;
sampleConnection.Open();
string cmd="select * from users where teacherid='"+name.Text.ToString()+"'and passwd='"+password.Text.ToString()+"'";
SqlCommand mycommand=new SqlCommand(cmd,sampleConnection);
SqlDataReader dr=mycommand.ExecuteReader();
if(dr.Read())
{
if(dr["role"].ToString()=="普通用户")
{
Session["uid"]=dr["teacherid"].ToString();
Session["role"]=dr["role"].ToString();
Response.Redirect("teachers.aspx");
}
else
{
Session["uid"]=dr["teacherid"].ToString();
Session["role"]=dr["role"].ToString();
Response.Redirect("users.aspx");
}
}
else
{
Response.Write("<script>alert(\"用户名或者密码错误!\")</script>");
}
sampleConnection.Close();
}
private void thbtn_Click(object sender, System.EventArgs e)
{
string searchstr=thddl.SelectedValue.ToString()+"="+thbox.Text.ToString();
Response.Redirect("teachersearch.aspx?"+searchstr);
}
private void pbtn_Click(object sender, System.EventArgs e)
{
string searchstr=pddl.SelectedValue.ToString()+"="+pbox.Text.ToString();
Response.Redirect("projectsearch.aspx?"+searchstr);
}
private void pabtn_Click(object sender, System.EventArgs e)
{
string searchstr=paddl.SelectedValue.ToString()+"="+pabox.Text.ToString();
Response.Redirect("papersearch.aspx?"+searchstr);
}
}
} 展开
private void logbut_Click(object sender, System.EventArgs e)
{
string connectionString=ConfigurationSettings.AppSettings["connectstr"].ToString();
SqlConnection sampleConnection = new SqlConnection(connectionString);
sampleConnection.ConnectionString = connectionString;
sampleConnection.Open();
string cmd="select * from users where teacherid='"+name.Text.ToString()+"'and passwd='"+password.Text.ToString()+"'";
SqlCommand mycommand=new SqlCommand(cmd,sampleConnection);
SqlDataReader dr=mycommand.ExecuteReader();
if(dr.Read())
{
if(dr["role"].ToString()=="普通用户")
{
Session["uid"]=dr["teacherid"].ToString();
Session["role"]=dr["role"].ToString();
Response.Redirect("teachers.aspx");
}
else
{
Session["uid"]=dr["teacherid"].ToString();
Session["role"]=dr["role"].ToString();
Response.Redirect("users.aspx");
}
}
else
{
Response.Write("<script>alert(\"用户名或者密码错误!\")</script>");
}
sampleConnection.Close();
}
private void thbtn_Click(object sender, System.EventArgs e)
{
string searchstr=thddl.SelectedValue.ToString()+"="+thbox.Text.ToString();
Response.Redirect("teachersearch.aspx?"+searchstr);
}
private void pbtn_Click(object sender, System.EventArgs e)
{
string searchstr=pddl.SelectedValue.ToString()+"="+pbox.Text.ToString();
Response.Redirect("projectsearch.aspx?"+searchstr);
}
private void pabtn_Click(object sender, System.EventArgs e)
{
string searchstr=paddl.SelectedValue.ToString()+"="+pabox.Text.ToString();
Response.Redirect("papersearch.aspx?"+searchstr);
}
}
} 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询