sercanparlak Posted May 2, 2006 Posted May 2, 2006 hi, i have problem with dataset. I create a form that has two textboxes, 1 datagrid and 4 buttons. textboxes are binding to dateset's 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" Quote
Arch4ngel Posted May 2, 2006 Posted May 2, 2006 I would go by adding the row directly into the data table and not through the BindingContext. Since everything is dynamicaly linked togheter, it will automaticaly be updated. I assume that you know how to add a row to a DataTable and assign them values. Cheers Quote "If someone say : "Die mortal !"... don't stay to see if he isn't." - Unknown "Learning to program is like going out with a new girl friend. There's always something that wasn't mentioned in the documentation..." - Me "A drunk girl is like an animal... it scream at everything like a cat and roll in the grass like a dog." - Me after seeing my girlfriend drunk and some of her drunk friend. C# TO VB TRANSLATOR
sercanparlak Posted May 3, 2006 Author Posted May 3, 2006 i tried that way too. this adds a row with empty values at the end; but binds the values to the current row. where is my mistake, someone please tell me. DataRow newRow = dataSet11.Tables[0].NewRow(); newRow["ID"]=textBox1.Text; newRow["ad"]=textBox2.Text; newRow["soyad"]=textBox3.Text; dataSet11.Tables[0].Rows.Add(newRow); Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.