How to concatenate data from a DataGridView and Save in a single field of the database

0

I want to concatenate and save the fields of a datagridview, however I do not know how to do this.

What I Have:

method:

public void Gravar()
{
    string strQuery;
    strQuery = "INSERT INTO Prato";
    strQuery += (" VALUES(");
    strQuery += ("seq_prato.NEXTVAL,");
    strQuery += ("'" + _nome + "',");
    strQuery += ("'" + _porcao + "',");
    strQuery += ("'" + _preco + "',");
    strQuery += ("'" + _descricao + "',");
    strQuery += ("'1'");
    strQuery += (")");
    clnBancoDados ObjClnBancoDados = new clnBancoDados();
    ObjClnBancoDados.ExecutaComando(strQuery);
}

Save button:

private void btnsalvar_Click(object sender, EventArgs e) 
{ 
    if ((txtnome.Text == "") || (txtpreco.Text == "") || (txtingrediente.Text == "")) 
    { 
        MessageBox.Show("Os Campos com * são de Preenchimento Obrigatórios!"); txtnome.Focus(); 
    }
    else
    {
        clnPrato Prato = new clnPrato();
        if (txtcod.Text != "")
        {
            Prato.cod = Convert.ToInt32(txtcod.Text);
            Prato.preco = Convert.ToInt32(txtpreco.Text);  
        }

        Prato.nome = txtnome.Text;
        Prato.porcao = comboporcao.Text;
        Prato.descricao = txtdescricao.Text;

        if (ObjOperacao == clnFuncoesGerais.Operacao.Inclusao)
        {
            Prato.Gravar();
            MessageBox.Show("Dados Gravados com Sucesso!", "Novo Produto " + txtnome.Text,
        MessageBoxButtons.OK, MessageBoxIcon.Information);
        } 
    } 
}

DataGridView:

public void formataGridView()
{
    dgvprato.ColumnCount = 2;
    dgvprato.Columns[0].Name = "CÓDIGO";
    dgvprato.Columns[1].Name = "INGREDIENTES";         
}

I want to concatenate the CODE column of all rows and save in _description.

    
asked by anonymous 16.10.2016 / 05:53

1 answer

3

I do not quite understand, but I think you're trying to do this:

Replace this: strQuery += ("'1'");

so: strQuery += (_código.ToString());

    
16.10.2016 / 08:55