示例#1
0
        public static object ExcuteQuery(string sql)
        {
            ConnectionDB connectionDB = new ConnectionDB();

            connectionDB.OpenConnection();
            SqlCommand com   = new SqlCommand(sql, con);
            object     check = com.ExecuteScalar();

            connectionDB.CloseConnection();
            return(check);
        }
示例#2
0
        public static DataTable LayDuLieuBang(string sql)
        {
            ConnectionDB connectionDB = new ConnectionDB();

            connectionDB.OpenConnection();

            DataTable dt = connectionDB.Select(CommandType.Text, sql);

            connectionDB.CloseConnection();

            return(dt);
        }
示例#3
0
        public static int LaySoDong(string sql)
        {
            ConnectionDB connectionDB = new ConnectionDB();

            connectionDB.OpenConnection();

            int row = connectionDB.ExecuteScalar(CommandType.Text, sql);

            connectionDB.CloseConnection();

            return(row);
        }
示例#4
0
        public static void RestoreDatabase(string path, string db)
        {
            string sql = string.Format("Restore database {0} from disk = '{1}'",
                                       db, path);

            ConnectionDB connectionDB = new ConnectionDB();

            connectionDB.OpenConnection();

            connectionDB.ExecuteNonQuery(CommandType.Text, sql);

            connectionDB.CloseConnection();
        }
示例#5
0
        //Thực thi một câu lệnh truy vấn trả về 1 kết quả duy nhất
        public static object ExecScalar(string sql)
        {
            ConnectionDB connectionDB = new ConnectionDB();

            connectionDB.OpenConnection();
            SqlCommand command = con.CreateCommand();

            command.CommandText = sql;
            object o = command.ExecuteScalar();

            connectionDB.CloseConnection();
            return(o);
        }
示例#6
0
        //Thực thi một câu lệnh truy vấn không quan tâm đến kết quả trả về.
        //Dùng cho insert, update, delete....
        public static void ExecNonQuery(string sql)
        {
            ConnectionDB connectionDB = new ConnectionDB();

            connectionDB.OpenConnection();

            SqlCommand command = con.CreateCommand();

            command.CommandText = sql;
            command.ExecuteNonQuery();

            connectionDB.CloseConnection();
        }
示例#7
0
        public static int ExcuteNonQuery(string sql)
        {
            ConnectionDB connectionDB = new ConnectionDB();

            connectionDB.OpenConnection();

            int nRow = 0;

            nRow = connectionDB.ExecuteNonQuery(CommandType.Text, sql);

            connectionDB.CloseConnection();

            return(nRow);
        }
示例#8
0
        public static int InsertUpdateDelete(string sql)
        {
            ConnectionDB p = new ConnectionDB();

            p.OpenConnection();

            int nRow = 0;

            nRow = p.ExecuteNonQuery(CommandType.Text, sql);

            p.CloseConnection();

            return(nRow);
        }
示例#9
0
        public int DaTonTai(string TenDangNhap)
        {
            string sql = string.Format("select count(*) from NGUOIDUNG where TenDangNhap = '{0}'", TenDangNhap);

            ConnectionDB connectionDB = new ConnectionDB();

            connectionDB.OpenConnection();

            int kq = connectionDB.ExecuteScalar(CommandType.Text, sql);

            connectionDB.CloseConnection();

            return(kq);
        }
示例#10
0
        public static string GenerateMa(string tenSP)
        {
            string sql = tenSP;

            ConnectionDB connectionDB = new ConnectionDB();

            connectionDB.OpenConnection();

            SqlParameter ma = new SqlParameter("@kq", SqlDbType.VarChar, 10);

            ma.Direction = ParameterDirection.Output;

            connectionDB.ExecuteNonQuery(CommandType.StoredProcedure, sql, ma);

            connectionDB.CloseConnection();

            return(ma.Value.ToString());
        }