Click here to Skip to main content
15,891,473 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I can't save all dataset's tables in database using dataadapter. When I try to save this, only first table is saved the others not.

What I have tried:

I get data from database using stored procedure in mysql workbrenck:

SQL
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


So, I do modification in tables data, then I try to save tables in datatable, but only first table is saved. :(. How can I save all datatable in database?

C#
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);
            }
        }
Posted
Updated 4-Feb-17 13:05pm

1 solution

Are all the data retrieved from the tables stored in the same dataset?
How are you storing the data you select? I can't see where you are storing it.

Maybe you should be using something like

dataset a = sql statement (SELECT * FROM materia_prima_ar order by 'DATA';)
dataset b = sql statement (SELECT * FROM materia_prima_amido order by 'DATA';)
etc (this is not proper code, but just trying to give you an idea how I think you should try to do it)

So you should have a dataset allocated for each select statement, then save each datset back to the table it was selected from after any changes.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900