sercanparlak
New member
- Joined
- Sep 14, 2004
- Messages
- 3
hi,
i have problem with dataset. I create a form that has two textboxes, 1 datagrid and 4 buttons. textboxes are binding to datesets columns.
my problem is when i want to add a new record to dataset with "BindingContext[dataSet11, "deneme"].AddNew()" it adds a new row at the end of dataset with null values. And updates current row with values that i want to add to the last row of dataset. thanks for helps.
You can see database preview at the bottom of code.
Here Is My Code
*******************************************************************
//Fills dataset
private void button1_Click(object sender, System.EventArgs e)
{
dataSet11.Clear();
sqlDataAdapter1.Fill(dataSet11);
dataGrid1.DataSource=dataSet11.Tables["deneme"];
}
private void dataGrid1_Click(object sender, System.EventArgs e)
{
this.BindingContext[dataSet11,"deneme"].Position=dataGrid1.CurrentRowIndex;
}
//delete current row
private void button4_Click(object sender, System.EventArgs e)
{
this.BindingContext[dataSet11, "deneme"].RemoveAt(this.BindingContext[dataSet11, "deneme"].Position);
}
//add new row, where the problem occurs.
private void button2_Click(object sender, System.EventArgs e)
{
BindingContext[dataSet11, "deneme"].AddNew();
BindingContext[dataSet11, "deneme"].EndCurrentEdit();
}
//update current row
private void button3_Click(object sender, System.EventArgs e)
{
//this.textBox1.DataBindings["Text"].BindingManagerBase.EndCurrentEdit();
BindingContext[dataSet11, "deneme"].EndCurrentEdit();
}
//update database
private void button5_Click(object sender, System.EventArgs e)
{
sqlDataAdapter1.Update(dataSet11);
}
*******************************************************************
-----------------------------------------
DB Before add
-----------------------------------------
ad soyad
--- --------
1- ahmet demir
2- veli gul
-----------------------------------------
I insert "cemal" "kaya"
DB After Add (before add currentrow was "ahmet demir")
-----------------------------------------
ad soyad
--- --------
1- cemal kaya
2- veli gul
3- "null" "null"
i have problem with dataset. I create a form that has two textboxes, 1 datagrid and 4 buttons. textboxes are binding to datesets columns.
my problem is when i want to add a new record to dataset with "BindingContext[dataSet11, "deneme"].AddNew()" it adds a new row at the end of dataset with null values. And updates current row with values that i want to add to the last row of dataset. thanks for helps.
You can see database preview at the bottom of code.
Here Is My Code
*******************************************************************
//Fills dataset
private void button1_Click(object sender, System.EventArgs e)
{
dataSet11.Clear();
sqlDataAdapter1.Fill(dataSet11);
dataGrid1.DataSource=dataSet11.Tables["deneme"];
}
private void dataGrid1_Click(object sender, System.EventArgs e)
{
this.BindingContext[dataSet11,"deneme"].Position=dataGrid1.CurrentRowIndex;
}
//delete current row
private void button4_Click(object sender, System.EventArgs e)
{
this.BindingContext[dataSet11, "deneme"].RemoveAt(this.BindingContext[dataSet11, "deneme"].Position);
}
//add new row, where the problem occurs.
private void button2_Click(object sender, System.EventArgs e)
{
BindingContext[dataSet11, "deneme"].AddNew();
BindingContext[dataSet11, "deneme"].EndCurrentEdit();
}
//update current row
private void button3_Click(object sender, System.EventArgs e)
{
//this.textBox1.DataBindings["Text"].BindingManagerBase.EndCurrentEdit();
BindingContext[dataSet11, "deneme"].EndCurrentEdit();
}
//update database
private void button5_Click(object sender, System.EventArgs e)
{
sqlDataAdapter1.Update(dataSet11);
}
*******************************************************************
-----------------------------------------
DB Before add
-----------------------------------------
ad soyad
--- --------
1- ahmet demir
2- veli gul
-----------------------------------------
I insert "cemal" "kaya"
DB After Add (before add currentrow was "ahmet demir")
-----------------------------------------
ad soyad
--- --------
1- cemal kaya
2- veli gul
3- "null" "null"