1.SQLServer
代码
2.Access
private static SqlConnection conn = new SqlConnection("server=(local);Integrated Security=SSPI;database=JSFguanliDB;");
private static SqlDataAdapter da;
private static SqlCommand cmd;
/// <summary>
/// 登陆操作
/// </summary>
/// <param name="userName">用户名</param>
/// <param name="passWord">密码</param>
/// <returns>是否成功</returns>
static public bool UserLogin(string userName, string passWord)
{
cmd = new SqlCommand("select yonghuming, yonghumima from denglubiao where yonghuming=@username and yonghumima=@passwd ", conn);
SqlParameter param = cmd.Parameters.Add("@username", SqlDbType.NVarChar, 50);
param.Value = userName;
param = cmd.Parameters.Add("@passwd", SqlDbType.NVarChar, 50);
param.Value = passWord;
conn.Open();
SqlDataReader rdr = cmd.ExecuteReader();
bool login = false;
try
{
if (rdr.HasRows)
login = true;
}
catch
{
login = false;
}
finally
{
conn.Close();
}
return login;
}
代码
private static OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; " +
"Data Source=JSFguanliDB.mdb");
private static OleDbDataAdapter da;
private static OleDbCommand cmd;
/// <summary>
/// 登陆操作
/// </summary>
/// <param name="userName">用户名</param>
/// <param name="passWord">密码</param>
/// <returns>是否成功</returns>
static public bool UserLogin(string userName, string passWord)
{
cmd = new OleDbCommand("select yonghuming, yonghumima from denglubiao where yonghuming=@username and yonghumima=@passwd ", conn);
OleDbParameter param = cmd.Parameters.Add("@username", OleDbType.VarChar, 50);
param.Value = userName;
param = cmd.Parameters.Add("@passwd", OleDbType.VarChar, 50);
param.Value = passWord;
conn.Open();
OleDbDataReader rdr = cmd.ExecuteReader();
bool login = false;
try
{
if (rdr.HasRows)
login = true;
}
catch
{
login = false;
}
finally
{
conn.Close();
}
return login;
}