public static void ExecutarComandoSQL(string strComando) { SqlConnection con = BDSQL.AbrirConexao(); using (SqlCommand command = new SqlCommand(strComando, con)) { command.ExecuteNonQuery(); } BDSQL.FecharConexao(); }
public static void ExecutarComandoSQL(string strComando, SqlParameter[] parametros) { FecharConexao(); SqlConnection con = BDSQL.AbrirConexao(); using (SqlCommand command = new SqlCommand(strComando, con)) { command.Parameters.AddRange(parametros); command.ExecuteNonQuery(); } BDSQL.FecharConexao(); }
public static DataTable ExecutarComandoLeituraSQLDataTable(string strComando) { var dt = new DataTable(); SqlConnection con = BDSQL.AbrirConexao(); using (SqlCommand command = new SqlCommand(strComando, con)) using (SqlDataReader reader = command.ExecuteReader()) { dt.Load(reader); } BDSQL.FecharConexao(); return(dt); }
public static List <Dictionary <string, string> > ExecutarComandoLeituraSQL(string strComando) { List <Dictionary <string, string> > registros = new List <Dictionary <string, string> >(); SqlConnection con = BDSQL.AbrirConexao(); using (SqlCommand command = new SqlCommand(strComando, con)) using (SqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { Dictionary <string, string> registro = new Dictionary <string, string>(); for (int i = 0; i < reader.FieldCount; i++) { registro.Add(reader.GetName(i), reader[reader.GetName(i)].ToString()); } registros.Add(registro); } } BDSQL.FecharConexao(); return(registros); }