using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using MySql.Data.MySqlClient;
namespace ConsoleApplication1
{
class Dao
{
private const string connstr = "Server=127.0.0.1;Port=3306;Database=mydata;User Id=root;Password=;Character Set=gbk";
public static bool login(string username, string password)
{
bool b = false;
using (MySqlConnection conn = new MySqlConnection(connstr))
{
using (MySqlCommand cmd = new MySqlCommand("select count(*) from t_user where username = @username, password = @password", conn))
{
cmd.Parameters.AddWithValue("username", username);
cmd.Parameters.AddWithValue("password", password);
conn.Open();
int i = Convert.ToInt32(cmd.ExecuteScalar());
if (i >= 1)
{
b = true;
}
}
}
return b;
}
public static ArrayList select_t_user(string sql, params MySqlParameter[] msp)
{
ArrayList al = new ArrayList();
using (MySqlConnection conn = new MySqlConnection(connstr))
{
using (MySqlCommand cmd = new MySqlCommand(sql, conn))
{
cmd.Parameters.AddRange(msp);
conn.Open();
using (MySqlDataReader mdr = cmd.ExecuteReader())
{
while (mdr.Read())
{
Hashtable ht = new Hashtable();
ht.Add("user_iden", mdr["user_iden"]);
ht.Add("user_name", mdr["user_name"]);
ht.Add("pass_word", mdr["pass_word"]);
al.Add(ht);
}
}
}
}
return al;
}
public static bool insertUpdateDelete(string sql, params MySqlParameter[] msp)
{
bool b = false;
using (MySqlConnection conn = new MySqlConnection(connstr))
{
using (MySqlCommand cmd = new MySqlCommand(sql, conn))
{
cmd.Parameters.AddRange(msp);
conn.Open();
int i = cmd.ExecuteNonQuery();
if (i >= 1)
{
b = true;
}
}
}
return b;
}
}
}
mysqlDao.cs
最新推荐文章于 2022-05-20 17:02:00 发布