Search code examples
c#sqlsql-serverrowwindows-forms-designer

DataGridview, first row, is becaming the rows with title


for example, the first row is the text salad|bacon|cheetos and the second 1|2|3 when i refresh my gridview, by calling the updateform function again, the rows become like this salad|bacon|cheetos salad|bacon|cheetos 1 |2 |3 i guess, this is a good explanation for what is happening, if its needed i can provide images of the form, now my code below :

private void UpdateForm()
{
    try
    {
        conexao = new SqlConnection(connectionString);
        strsql = "Select des_placa,cod_caminhao_integracao,cod_caminhao_carregamento from caminhao";
        da = new SqlDataAdapter(strsql, conexao);
        DataTable ds = new DataTable();
        conexao.Open();
        da.Fill(ds);
      
        dataGridView1.DataSource= ds;   
        comboBox1.DataSource = ds;
        comboBox1.DisplayMember = "des_placa";
        comboBox1.ValueMember = "des_placa";
        comboBox1.AutoCompleteMode = AutoCompleteMode.Suggest;
        comboBox1.AutoCompleteSource = AutoCompleteSource.ListItems;
        Placa.DataBindings.Clear();
        cod_integracao.DataBindings.Clear();
        Cod_carregamento.DataBindings.Clear();
        Placa.DataBarregamento.DataBindings.Add("Text", ds, "cod_caminhao_carregamento");

        strsql = "Select des_placa,cod_caminhao_carregamento,cod_caminhao_integracao from caminhao where des_placa = '" + comboBox1.Text + "';";
        SqlCommand cmd = new SqlCommand(strsql, conexao);
        Placa.Text = "des_placa";
        Cod_carregamento.Text = "cod_caminhao_carregamento";
        cod_integracao.Text = "cod_caminhao_integracao";
        cmd.ExecuteNonQuery();
    }            
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
    finally
    {
        conexao.Close();
        conexao = null;
        cmd = null;
    }
}

Solution

  • found out what line of code is doing that, so i deleted because it's unnecessary, if someone knows how to explain why, because i don't i'm kinda new to working with c# and windowsform

    strsql = "Select des_placa,cod_caminhao_carregamento,cod_caminhao_integracao from caminhao where des_placa = '" + comboBox1.Text + "';";
    SqlCommand cmd = new SqlCommand(strsql, conexao);
    Placa.Text = "des_placa";
    Cod_carregamento.Text = "cod_caminhao_carregamento";
    cod_integracao.Text = "cod_caminhao_integracao";
    cmd.ExecuteNonQuery();