[英]Add manually rows to DataGridView c#
我有一个 DataGridView 可以读取应该从数据库中显示的所有数据,这很好用,但我想手动添加另外两行。 我怎样才能做到这一点?
这是我的表单,我想添加这两行的位置在最后:
代码:
strsql = "";
strsql = strsql + " SELECT CARACT, DENOMI";
strsql = strsql + " FROM TC";
strsql = strsql + " WHERE CARACT >= '500' AND CARACT != 'MAT'
AND CARACT != 'KGN' AND CARACT != 'LON' AND CARACT != 'MAR' AND
CARACT != 'PES' AND CARACT != 'T-P' ORDER BY CARACT";
comando = new SqlCommand(strsql, conexion);
adapter = new SqlDataAdapter(comando);
table = new DataTable();
comando.CommandText = strsql;
table.Columns.Clear();
table.Clear();
adapter.Fill(table);
conexion.Close();
DataRow rowD = new DataRow();
rowD.Cells[0].Value = "Peso%";
rowD.Cells[1].Value = "Peso%";
table.Rows.Add(rowD);
return table;
添加行的正确方法是:
var newRow = table.Rows.Add();
newRow["ColuEmail"] = "rb.coqueiro@gmail.com";
newRow["ColumClientName"] = "Renato Coqueiro";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.