I have read several open cases of this type but I do not really see one that fits my case. Well I raise my case;
I have a DataGridview which, by consulting the BD, I filled it and I want to add rows through TextBox that are in the same form.
My code to add rows is:
string[] fila = new string[] { txtidproducto.Text, txtproducto.Text,txtmarca.Text,txtdescripcion.Text,txtcantidad.Text,txtprecio.Text};
dtgv.Rows.Add(fila);
If I execute that code it gives me an error that "Rows can not be programmatically added to the DataGridView's rows collection when the control is data-bound." The cases that I have seen of this is that the user tries to add rows to the DataGridView that already had rows added by means of query, then he wants to add other rows to him by another query and they realize it by means of array (really the subject of arrays do not handle it very well) And besides not wanting to make a second consultation but a direct insertion, I think those cases do not suit mine. Please help.
so I fill in the DataGridView:
string sql2 = @"SELECT DISTINCT cabeza.Id_producto,detalle.Producto,detalle.Marca,detalle.Descripcion,cabeza.Cantidad, cabeza.Precio FROM Tab_entrada_mercancia_detalle AS cabeza INNER JOIN Tab_productos AS detalle ON cabeza.Id_producto = detalle.Id_producto where cabeza.Id_entrada=@numeroentrada";
SqlCommand cmd2 = new SqlCommand(sql2, cn);
cmd2.Parameters.AddWithValue("@numeroentrada", txtSalidaEntrada.Text);
SqlDataAdapter da = new SqlDataAdapter(cmd2);
DataTable dt = new DataTable();
da.Fill(dt);
dtgv.DataSource = dt;