Groups | Blog | Home
all groups > dotnet windows forms databinding > may 2008 >

dotnet windows forms databinding : Newly added Row fails to update



Morris Neuman
5/23/2008 8:39:01 PM
I have a windows form with a Dataset with only one table bound to Details
View controls, all created in VS2005 with designer. I added a button to
create a new record and issue a this.mBDetailsBindingSource.AddNew(); to
create a new blank row in the table and then fill the controls with their
default values. (There is no BindingNavigator for these controls.) Then
when a Save button is pressed I call Validate(), EndEdit and the Update() but
the row does not get sent to the data base.
If I edit an existing record and click Save the update for that row works.

How do I get the new row to be added to the SQL Database table?

Thanks
v-lliu@online.microsoft.com
5/26/2008 3:55:53 AM
Hi Morris,

Based on my understanding, you are able to update the existing records but
cannot insert new records to the database. If I'm off base, please feel
free to let me know.

I perform a test but couldn't reproduce the problem on my side. The main
steps of my test are as follows:
1. Use "Data Source Configuration Wizard" to add a DataSet containing a
DataTable into the project(select menu Data| Add New Data Source¡­), which
also generates a TableAdapter for the DataTable.
2. Open the "Data Sources window" (select menu Data | Show Data Sources).
3. From the Data Sources window, click the drop down button on the right
of the DataTable and select "Details" and then drag the DataTable onto a
Form, which generates several controls, a DataSet instance, a BindinSource,
a TableAdapter as well as a BindingNavigator.
4. Delete the BindingNavigator from the Form.
5. Add two Buttons on the Form and handle the Click event of these two
Buttons.
// add a new record
private void button1_Click(object sender, EventArgs e)
{
this.bindingSource1.AddNew();
}
// save changes back to DB
private void button2_Click(object sender, EventArgs e)
{
this.Validate();
this.bindingSource1.EndEdit();
this.tableAdapter1.Update(this.dataSet1.Table1);
}

Since I couldn't reproduce the problem using the same lines of code as
yours, I suspect the reason of your problem is that the InsertCommand is
missing in the TableAdapter for your DataTable. I recommend you check
whether there's an InsertCommand in the TableAdapter or not. To do this:

1. In the Solution Explorer, double click the DataSet file(.xsd file) to
open the DataSet designer.
2. In the DataSet designer, click on the xxxTableAdapter panel and switch
to the Properties window.
3. In the Properties window, check the value of the InsertCommand property.

If the InsertCommand property is (none), click the new option in the drop
down list, and then specify the 'Command Text' and 'Parameters' properties
for the InsertCommand.

Please try my suggestion and let me know the result.

If the problem is still not solved, you may reproduce the problem in a
simple project and send it to me. To get my actual email address, remove
'online' from my displayed email address.

Sincerely,
Linda Liu
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msdnmg@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
v-lliu@online.microsoft.com
5/28/2008 12:56:31 AM
Hi Morris,

How about the problem now?

If the problem is still not solved, please feel free to let me know.

Thank you for using our MSDN Managed Newsgroup Support Service!

Sincerely,
Linda Liu
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msdnmg@microsoft.com.

This posting is provided "AS IS" with no warranties, and confers no rights.
AddThis Social Bookmark Button