classtb_EmpInfoMenthod{//数据库连接字符串publicstaticstringConn="Database='supermarker';DataSource='localhost';UserId='root';Password='123456';charset='utf8';pooling=true...
class tb_EmpInfoMenthod
{
//数据库连接字符串
public static string Conn = "Database='supermarker';Data Source='localhost';User Id='root';Password='123456';charset='utf8';pooling=true";
public int Conn_mysql(string username, string userpassword)
{
int flog = -2;
MySqlConnection mysql_con = new MySqlConnection();
MySqlCommand mda;
mysql_con.ConnectionString = Conn;
try
{
mysql_con.Open();
string sql_sentence = "select * from supermarker where username='" + username + "' and userpassword='" + userpassword + "';";
mda = new MySqlCommand(sql_sentence, mysql_con);
// MySqlDataAdapter mda = new MySqlDataAdapter(sql_sentence, mysql_con);
object ds = mda.ExecuteScalar();
if (ds == null)
{
//用户密码错误
return 0;
}
else
{
//查询成功
return 1;
}
}
catch (Exception)
{
//异常错误
return -1;
}
finally
{
mysql_con.Close();
}
return flog;
}
}
展开