static string ConnString = ConfigurationManager.ConnectionStrings["ConnString"].ConnectionString;
public static DataTable GetDataTable(string sql)
{
SqlConnection sqlcon = null;
try
{
sqlcon = new SqlConnection(ConnString);
sqlcon.Open();
SqlDataAdapter sqldata = new SqlDataAdapter(sql, ConnString);
DataTable dt = new DataTable("newTable");
sqldata.Fill(dt);
sqlcon.Close();
return dt;
}
catch (Exception ex)
{
throw ex;
}
finally
{
sqlcon.Close();
}
}
protected void butNext_Click(object sender, EventArgs e)
{
this.lbltext.Text= this.ListAllUserNameAndPass(this.txtName.Text,this.txtPass.Text);
}
public static String ListUserNameAndPass(string name,int pass)
{
Student t = null;
string nn=""
string sql = "select top 1 * from Student where UserName='"+name+"' and Pass='"+pass+"'";
DataTable dt = GetDataTable(sql);
foreach (DataRow dr in dt.Rows)
{
t = new Student();
t.UserName = dr["UserName"].ToString();
t.Pass =dr["Pass"].ToString();
if (t.UserName != null)
{
//提示登录成功
nn="登录成功";
}
else{
//提示登录失败
nn="登录失败 ";
}
}
return nn;
}