Save dataset C#

Asked

Viewed 266 times

4

I’m searching several tables from the database for a Dataset through a Stored Procedure in the MySQL using the Mysql Workbrenck, but when saving only the first table is saved, my code:

Stored Procedure:

CREATE DEFINER=`root`@`localhost` PROCEDURE `Tabelas_Materia_Prima`()
BEGIN

    SELECT * FROM materia_prima_ar order by 'DATA';
    SELECT * FROM materia_prima_amido order by 'DATA';
    SELECT * FROM materia_prima_art order by 'DATA';
    SELECT * FROM materia_prima_umidade order by 'DATA';
    SELECT * FROM materia_prima_pol order by 'DATA';
    SELECT * FROM materia_prima_infeccao order by 'DATA';
    SELECT * FROM materia_prima_imp_veg order by 'DATA';
    SELECT * FROM materia_prima_imp_min order by 'DATA';
    SELECT * FROM materia_prima_fosfato order by 'DATA';
    SELECT * FROM materia_prima_fibra order by 'DATA';
    SELECT * FROM materia_prima_dextrana order by 'DATA';    

END

Method to save Dataset again:

public void Salvar_Procedure(DataSet Dados, string Nome_Procedure)
{
     MySqlConnection Conexao = new MySqlConnection(StringConexao);

     //OdbcConnection Conexao = new OdbcConnection("DSN=YasFashion_Sacoleiro_DB");

     MySqlCommand Comando = new MySqlCommand();
     Comando.Connection = Conexao;
     Comando.CommandType = CommandType.StoredProcedure;
     Comando.CommandText = Nome_Procedure;
     MySqlDataAdapter Meu_Adaptador = new MySqlDataAdapter(Comando);

     //OdbcDataAdapter Meu_Adaptador = new OdbcDataAdapter("SELECT * FROM " + Nome_Tabela, Conexao);

     try
     {
          Conexao.Open();

          MySqlCommandBuilder Comando01 = new MySqlCommandBuilder(Meu_Adaptador);

         //OdbcCommandBuilder Comando = new OdbcCommandBuilder(Meu_Adaptador);

         Meu_Adaptador.Update(Dados);

         Conexao.Close();
      }
      catch (Exception ex)
      {
           MessageBox.Show("Erro de salvamento: \n" + ex);
      }
}
  • You want to use the PROCEDURE Table_materia_press() as a return select of all the select you have in it?

1 answer

0

Does your Proc execute when it’s called straight from the BDS? If not, give a look if it is not getting lost with the name of the columns of the different types of tables.

You can compose select by explicit fields with the same name for each query. From the looks of it, the object you save is as per the first select.

You can use all of them in a View using sql UNION to put all the data as if it were a single table.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.