请大家看上小弟我的代码哪来出错了
请大家看下我的代码哪来出错了?
在做一个系统,正在做登陆部分,因为经常要连接数据库,就自己写了个类
在做一个系统,正在做登陆部分,因为经常要连接数据库,就自己写了个类
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;
}
}
catch (Exception ex)