问题描述
你好,
我有2个datagridviews。如果你向第一个添加一个arctle,我将用button_click保存到第二个。但我得到这个错误:
NullReferenceException未处理。
这是我的代码:
private void button1_Click(object sender,EventArgs e)
{
string cs = ConfigurationManager.ConnectionStrings [cs]。ConnectionString;
SqlDataAdapter adapter = new SqlDataAdapter(SELECT [ArtikelID] INTO [STA]。[Messung_Artikel] FROM [STA]。[Compukat],cs);
SqlCommandBuilder commandBuilder = new SqlCommandBuilder(adapter);
DataTable table = new DataTable();
table.Locale = CultureInfo.InvariantCulture;
adapter.Fill(table);
bindingSource.DataSource = table;
this.messung_ArtikelDataGridView。 DataSource = bindingSource;
this.messung_ArtikelDataGridView.ReadOnly = false;
foreach(this.messung_ArtikelDataGridView.Columns中的DataGridViewColumn列)
{
column.ReadOnly = column.Name!=ID? false:true;
}
}
感谢您的回答。
Greetz
克里斯
Hello,
i have got 2 datagridviews. If you add an arctle to the first, i what to save it with a button_click into the second. But i get this error:
NullReferenceException was unhandled.
Here is my code:
private void button1_Click(object sender, EventArgs e)
{
string cs = ConfigurationManager.ConnectionStrings["cs"].ConnectionString;
SqlDataAdapter adapter = new SqlDataAdapter("SELECT [ArtikelID] INTO [STA]. [Messung_Artikel] FROM [STA].[Compukat]", cs);
SqlCommandBuilder commandBuilder = new SqlCommandBuilder(adapter);
DataTable table = new DataTable();
table.Locale = CultureInfo.InvariantCulture;
adapter.Fill(table);
bindingSource.DataSource = table;
this.messung_ArtikelDataGridView.DataSource = bindingSource;
this.messung_ArtikelDataGridView.ReadOnly = false;
foreach (DataGridViewColumn column in this.messung_ArtikelDataGridView.Columns)
{
column.ReadOnly = column.Name != "ID" ? false : true;
}
}
Thanky for your answer.
Greetz
Chris
推荐答案
这篇关于将一个数据网格的内容保存到另一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!