Search code examples
c#datagridviewtextboxinsert

how to insert data from textboxes to datagridview in C#


I have a task i.e i have to insert data from text boxes to datagridview and then save the datagridview data into database with multiple rows what i added from text boxes to datagridview.i tried some code but it is working for first row only i cont add more than one row.can any one help me how can i do this?.

  private void btnAdd_Click(object sender, EventArgs e)
    {
        dgvUom.Rows[0].Cells["UomType"].Value = txtUomtyp.Text;
        dgvUom.Rows[0].Cells["UOmDesc"].Value = txtUomDesc.Text;
    }

Solution

  •     private void btnAdd_Click(object sender, EventArgs e)
        {
            string firstColum = txtUomtyp.Text;
            string secondColum = txtUomDesc.Text;
            string[] row = { firstColum, secondColum };
            dgvUom.Rows.Add(row);
        }