DBaccess
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Text;
//using System.Windows.Forms;
namespace keraoke
{
class DBAccess
{
public SqlConnection Getconnection()
{
return new SqlConnection("server="+server+";; user;");
}
public bool Checklogin(string name, string pass)
{
SqlConnection con= Getconnection();
SqlCommand cm= new SqlCommand("select * from account where username='"+name+"' and password='"+pass+"'",con);
con.Open();
SqlDataReader dr= cm.ExecuteReader();
if(dr.HasRows)
{
con.Close();
return true;
}
else
{
con.Close();
return false;
}
}
public bool CheckAdmin(string name, string pass)
{
SqlConnection con = Getconnection();
SqlCommand cmd = new SqlCommand("select role from account where username='"+name+"' and password='"+pass+"'", con);
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
if (dr.HasRows)
{
dr.Read();
//MessageBox.Show(dr.GetString(0), "thongbao");
if (dr.GetString(0).Substring(0,5) == "admin")
{
con.Close();
return true;
}
}
con.Close();
return false;
}
public static string server = "pcleduy";
public static string database = "karaoke";
public static string userid = "sa";
public static string password = "quangduy";
}
}
Bạn đang đọc truyện trên: AzTruyen.Top