c#.net将数据填充到datagridview中已定义的列 [英] c#.net fill data to already defined columns in datagridview
本文介绍了c#.net将数据填充到datagridview中已定义的列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
如何将数据插入到datagridview中已定义的列中
我有一个带有列代码和描述的datagridview.我试图用以下代码填充它,但没有将其填充到相应的列中.
Hi All,
How to insert data to already defined columns in datagridview
I have a datagridview with columns code and description.I am trying to fill it with the following code but its not filling it to the respective columns.
private void frmFind_Load(object sender, EventArgs e)
{
DataSet ds = new DataSet();
string sql = "SELECT cuccd,cucna FROM incoun";
using (SqlConnection connection = ConnectionManager.GetConnection())
{
SqlCommand command = new SqlCommand(sql, connection);
SqlDataAdapter adp = new SqlDataAdapter(command);
adp.Fill(ds,"INCOUN");
dataGridView1.AutoGenerateColumns = false;
dataGridView1.DataSource = ds.Tables["incoun"];
}
}
推荐答案
当AutoGenerateColumns设置为false时,您必须在每个列中指定字段名称
转到编辑列",选择一列,然后将"DataPropertyName"设置为数据表中的列名,然后分配数据源
when AutoGenerateColumns is set to false, you must have specified the field names in each of the column
Go to ''Edit Columns'', select a column and set the ''DataPropertyName'' to the column name in your data table & then assign the datasource
这篇关于c#.net将数据填充到datagridview中已定义的列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文