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); }
public static DataTable LayDuLieuBang(string sql) { ConnectionDB connectionDB = new ConnectionDB(); connectionDB.OpenConnection(); DataTable dt = connectionDB.Select(CommandType.Text, sql); connectionDB.CloseConnection(); return(dt); }
public static int LaySoDong(string sql) { ConnectionDB connectionDB = new ConnectionDB(); connectionDB.OpenConnection(); int row = connectionDB.ExecuteScalar(CommandType.Text, sql); connectionDB.CloseConnection(); return(row); }
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(); }
//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); }
//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(); }
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); }
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); }
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); }
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()); }