Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm Data Binding / July 2008

Tip: Looking for answers? Try searching our database.

Newly added Row fails to update

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Morris Neuman - 24 May 2008 04:39 GMT
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
Morris
Linda Liu[MSFT] - 26 May 2008 04:55 GMT
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.
Linda Liu[MSFT] - 28 May 2008 01:56 GMT
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.
rockzZ26 - 01 Jul 2008 19:56 GMT
Hi Linda,

i am facing similar problem. I have been trying to insert some data from a
form to the sql server database. i have tried both ways using command and
using data table adapter. I have even coded everything by hand and have tried
the methodology you specified but when i check the database table, no row is
ever added and yet i get no errors or exceptions.

I am confused because of this behaviour. Any help will be appreciated.

> Hi Morris,
>
[quoted text clipped - 15 lines]
>
> This posting is provided "AS IS" with no warranties, and confers no rights.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.