日期:2014-05-17 浏览次数:20890 次
public class SQLcon
{
private string con = "server=(local);user id=sa;password=sa;database=student";
public SqlConnection ConnectToDatabase()
{
return new SqlConnection(con);
}
public bool Login(string uid, string pwd, SqlConnection mycon) //判断是否登陆成功
{
if (mycon.State != ConnectionState.Open)
{
MessageBox.Show("数据库未打开");
try
{
mycon.Open();
SqlCommand login = new SqlCommand();
string str = " select UserID from UserLogin where UserName='" + uid + "' and PassWord ='" + pwd + "' ";
login.CommandText = str;
login.Connection = mycon;
SqlDataReader result = login.ExecuteReader();
mycon.Close();
if (result.HasRows)
{
return true;
}
else
{
return false;
}
}