我已datagridview
与datatable
( Growns ) 绑定。我的主要目标是,该用户可以使用datagridview
(dataGridView1),填充和更新数据,当单击button
SAVE时,所有数据都将保存到数据表中,因为我需要它来做进一步的工作。
一切正常,除了将数据保存到 datatable。我究竟做错了什么?
这是我的代码:
private void Form2_Load(object sender, EventArgs e) {
// TODO: This line of code loads data into the 'tekmovalecDataSet.Odrasli' table. You can move, or remove it, as needed.
this.grownsTableAdapter.Fill(this.competitorDataSet.Odrasli);
}
private void buttonSave_Click(object sender, EventArgs e) {
if (EmptySpace())
{
CompetitorDataSet.OdrasliRow newGrownsRow = competitorDataSet.Growns.NewGrownsRow();
newGrownsRow.StN = textStN.Text;
newGrownsRow.Name = textN.Text;
newGrownsRow.Surname = textSN.Text;
newGrownsRow.Club = textC.Text;
newGrownsRow.YBirth = textYB.Text;
competitorDataSet.Growns.Rows.Add(OdrasliNova);
competitorDataSet.Growns.AcceptChanges();
this.dataGridView1.DataSource = competitorDataSet.Growns;
this.Validate();
this.grownsBindingSource.EndEdit();
if (dataGridView1.BindingContext[competitorDataSet.Growns] != null)
{
dataGridView1.BindingContext[competitorDataSet.Growns].EndCurrentEdit();
}
this.grownsTableAdapter.Update(competitorDataSet.Odrasli);
this.grownsTableAdapter.Adapter.AcceptChangesDuringUpdate = true;
}
else
{
MessageBox.Show("Fill ALL data about competitor!");
}
}
PS:当我手动填写时datatable
,填写表格打开,datagridview
所以我想是连接的......datatable
datagridview
PS2.: boolEmptySpace
工作正常。