Vous êtes sur la page 1sur 5

7/3/2016 [RESOLVED] Tableadapter Update Command only works once!?

@-VBForums

User Name Password Log in Help Register

Remember Me?

Forum What's New?

New Posts FAQ Calendar Forum Actions Quick Links Advanced Search

VBForums Visual Basic Visual Basic .NET [RESOLVED] Tableadapter Update Command only works once!?@

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to
proceed. To start viewing messages, select the forum that you want to visit from the selection below. Featured

Results 1 to 11 of 11 * Storing
Data in the
Cloud
Thread: [RESOLVED] Tableadapter Update Command only works once!?@ Learn step-
Tweet by-step how to
setup data in
Thread Tools Display the cloud and
use it within
#1 an application.
Apr 4th, 2008, 04:48 PM
* Accessing
beamer4lyf Cloud Data
[RESOLVED] Tableadapter Update Command only works once!?@ using an
Thread Starter OData Web
New Member
I have a SQL database created in VS2005 (not express ed.) I have one table with Name and Age Fields. I Service
have two text boxes databound to these two columns in my table. On the command click of a button on Learn to
Join Date: Apr 2008
my form i have the following code. build a web
Posts: 15
service and an
bindingsource1.endedit () application
tabeadapter.update(mydataset.mytablename) that consumes
your data that
is stored in the
in a try catch block.
cloud.
i can add the rows to the database but when i go to update the row after i have made a change i get an * Windows
error. the error states that i called the update command incorrectly. the weird part is that this works the Mobile
first time i add something to the database using the Development
Center
bindingsource1.addnew CodeGuru's
tableadapter.update(mydataset.mytablename) Windows
Mobile
it adds the row to the database, but if i make a change to that row, i cannot call the update command Development
again without getting an error. Center
provides
any help is appreciated. I will post the code later when i get home. articles on
building
Thanks! Modern
Windows
Store Apps
Reply With Quote and more.
Share
on
* HTML5
Google+ Development
Apr 4th, 2008, 09:47 PM #2 Center
Our portal
jmcilhinney for articles,
Re: Tableadapter Update Command only works once!?@
.NUT videos, and
Tell us EXACTLY what the error message says. news on
HTML5, CSS3,
and JavaScript

Join Date: May 2005


Location: Sydney, Australia Click Here to
Posts: 92,853 Expand Forum
to Full Width

2007-2016 Survey posted


by VBForums.
Why is my data not sav ed to my database? | MSDN Data Walk throughs
MSDN "How Do I?" Videos: VB | C#
VBForums Database Dev elopment FA Q
My CodeBank Submissions: VB | C#
My Blog: Data A mong Multiple Forms (3 parts) | WP8 Turnstile Feather Transition with Piv ot Control
Beginner Tutorials: VB | C# | SQL

Share Reply With Quote


on
Google+
Apr 7th, 2008, 03:37 AM #3

beamer4lyf
Re: Tableadapter Update Command only works once!?@
Thread Starter
New Member
Code:
Join Date: Apr 2008 Try
Me.Validate()
Posts: 15
Me.NameBindingSource.EndEdit()
Me.NameTableAdapter.Update(Me.DsTest.name)

MsgBox("Update successful")
Catch ex As Exception
MessageBox.Show("update failed")

End Try

the Error i receive is a system.invalidoperationexection... reads " Update requires a valid UpdateCommand
when passed DataRow collection with modified rows." and the following line of code is highlighted..
"Me.NameTableAdapter.Update(Me.DsTest.name)"

http://www.vbforums.com/showthread.php?516858-RESOLVED-Tableadapter-Update-Command-only-works-once! 1/5
7/3/2016 [RESOLVED] Tableadapter Update Command only works once!?@-VBForums

the help describes the error with the following, however i feel as though i am simply updating the modified
rows to the database after calling the end edit for the binding source. The update command works the
first time, but fails the second time.

"TableAdapters require valid UPDATE, INSERT, and DELETE commands to perform a successful save
operation.
TableAdapters generate INSERT, UPDATE, and DELETE statements based on the original SELECT
statement entered into the wizard. In some situations, the SELECT statement does not provide enough
information for the adapter to generate the commands necessary to create the INSERT, UPDATE, and
DELETE commands required for a successful save. This often occurs when the database table does not
have a primary key column, or the SELECT command uses JOINS. For more information, see How to: Edit
TableAdapters."

thanks!

Share Reply With Quote


on
Google+
Apr 7th, 2008, 03:39 AM #4

beamer4lyf
Re: Tableadapter Update Command only works once!?@
Thread Starter
New Member The more wordy version of the error:

Join Date: Apr 2008


Posts: 15
Code: at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, Int
Ptr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNat
iveMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32
pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason,
ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, Appl
icationContext context)
at System.Windows.Forms.Application.Run(ApplicationContext context)
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicat
ionModel()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String
[] commandLine)
at databasetest1.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53
493378c1071.vb:line 81
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity,
String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, Context
Callback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()

Share Reply With Quote


on
Google+
Apr 7th, 2008, 04:05 AM #5

jmcilhinney
Re: Tableadapter Update Command only works once!?@
.NUT
This is why you need to provide the error message to us that the IDE provides to you. They are a
diagnostic tool and if you want us to diagnose the issue then we need that information. In this case it's
all we need:

Join Date: May 2005 Update requires a valid UpdateCommand when passed DataRow collection with modified rows.
Location: Sydney, Australia
Posts: 92,853
Your TableAdapter has no UpdateCommand, which suggests that the Data Source Wizard was unable to
generate one. That would happen because either the query contains a JOIN of two or more tables or else
the query doesn't return a primary key.

Does this TableAdapter correspond directly to a table in the database? Does that table have a primary
key? If not then how is the system to uniquely identify the records in order to know which one to
update? The same goes for deleting.

If you do need to update the database using such a TableAdapter that was generated from either a join,
a table with no primary key or query that returns no primary key then it's up to you to create the
UpdateCommand and DeleteCommand yourself, explicitly identifying the records uniquely so that the
correct ones get updated and deleted.

2007-2016

Why is my data not sav ed to my database? | MSDN Data Walk throughs


MSDN "How Do I?" Videos: VB | C#
VBForums Database Dev elopment FA Q
My CodeBank Submissions: VB | C#
My Blog: Data A mong Multiple Forms (3 parts) | WP8 Turnstile Feather Transition with Piv ot Control
Beginner Tutorials: VB | C# | SQL

Share Reply With Quote


on
Google+
Apr 7th, 2008, 04:12 AM #6

http://www.vbforums.com/showthread.php?516858-RESOLVED-Tableadapter-Update-Command-only-works-once! 2/5
7/3/2016 [RESOLVED] Tableadapter Update Command only works once!?@-VBForums

beamer4lyf Re: Tableadapter Update Command only works once!?@


Thread Starter Thank You for your kind response. I went searching further and you are were correct. I do not currently
New Member
have an insert, delete or update query in my dataset. Rather I had just a FIll / Get Data query. Please
Join Date: Apr 2008
see below for the steps i went through to try and generate a valid update,delete and insert command.
Posts: 15
I loaded the wizard and selected new dataset.

i then set the appropriate connect string settings

selected the database objects i wanted.

but when i click finish and then go to view the dataset in the designer window, i see only a fill, get data
statement

so i right click on the tableadapter and select properties to see what we have there.. it appears
everything is checked appropriately..

so then i go to the add query builder to see if i cant add the appropriate query. after running the wizard
and selecting to have valid insert, update and delete commands,

I STILL have a fill, get data statement and nothing else... except when i look at the properties of the
adapter, i see valid update and insert and delete commands...

I do have a primary key set for my table.. is this correctly done? do i need to do it for the dataset when i
create it? My impression was that the dataset becomes an in memory copy of the datatable.. thus taking
the key relationships as well..

i follow the examples online to the T and yet i still end up with this difference.. Please help guide me
towards correcting this problem. Thank you in advance for your dedication to my increasing my
knowledge of this problem.

-B

Share Reply With Quote


on
Google+
Apr 7th, 2008, 04:15 AM #7

jmcilhinney
Re: Tableadapter Update Command only works once!?@
.NUT
OK, now you're posting the same stuff in two threads and one of them's not even yours. One thread per
topic and one topic per thread please. It's a waste of my time, your time and anybody else who might be
trying to track down the same information if the same question is being answered in multiple threads.

Join Date: May 2005


Location: Sydney, Australia
Posts: 92,853

2007-2016

Why is my data not sav ed to my database? | MSDN Data Walk throughs


MSDN "How Do I?" Videos: VB | C#
VBForums Database Dev elopment FA Q
My CodeBank Submissions: VB | C#
My Blog: Data A mong Multiple Forms (3 parts) | WP8 Turnstile Feather Transition with Piv ot Control
Beginner Tutorials: VB | C# | SQL

Share Reply With Quote


on
Google+
Apr 7th, 2008, 04:18 AM #8

beamer4lyf
Re: Tableadapter Update Command only works once!?@
Thread Starter
New Member my apologies. I will forward any responses to what i have posted in the other thread to this thread as it
is mine. The double posting was unintentional.
Join Date: Apr 2008
Posts: 15

Share Reply With Quote


on
Google+
Apr 7th, 2008, 04:20 AM #9

beamer4lyf
Re: Tableadapter Update Command only works once!?@
Thread Starter
New Member close up of the code generated..

Join Date: Apr 2008


Posts: 15

http://www.vbforums.com/showthread.php?516858-RESOLVED-Tableadapter-Update-Command-only-works-once! 3/5
7/3/2016 [RESOLVED] Tableadapter Update Command only works once!?@-VBForums

why only fill, getby data shows up in query list when its in the properties of the table adapter...?

Share Reply With Quote


on
Google+
Apr 7th, 2008, 04:24 AM #10

jmcilhinney
Re: Tableadapter Update Command only works once!?@
.NUT
Because they are the only methods that execute queries. The Update method is what executes the
DeleteCommand, InsertCommand and UpdateCommand, which are not queries. That query list shows all
the methods that correspond to SELECT statements. You can add more queries if you want to allow the
user to specify different combinations of parameters to filter the data. there will still only ever be one
Join Date: May 2005 DeleteCommand, one InsertCommand and one UpdateCommand though, and they will always be executed
Location: Sydney, Australia by calling the Update method.
Posts: 92,853

2007-2016

Why is my data not sav ed to my database? | MSDN Data Walk throughs


MSDN "How Do I?" Videos: VB | C#
VBForums Database Dev elopment FA Q
My CodeBank Submissions: VB | C#
My Blog: Data A mong Multiple Forms (3 parts) | WP8 Turnstile Feather Transition with Piv ot Control
Beginner Tutorials: VB | C# | SQL

Share Reply With Quote


on
Google+
Apr 7th, 2008, 04:31 AM #11

beamer4lyf
Re: Tableadapter Update Command only works once!?@
Thread Starter
New Member Yes. Thank you JMCillhinney. I was investigating the issue further and decided to try and add a new
Query to contain the update method. I went to the designer window and selected the table adapter and
Join Date: Apr 2008 right clicked to show add -> Query. I selected use SQL statement then selected update. Now at this
Posts: 15 point i noticed that the code was already filled in for me with a valid SQL statment on how to select and
update the rows according to their key value. The difference here is that in my original dataset i didnt
have this pre-populated code. when creating that dataset i remember i only selected tables when asked
what i wanted to have the dataset contain. this time i selected everything, including stored proceedures
and then i added them manually and it works. I test run the program and no error. I ran a build and tried
it out of VS and it worked as well.

Thank you so much for your guidance. And sorry again for the double posting.

Last edited by beamer4lyf; Apr 7th, 2008 at 11:22 AM.

Share Reply With Quote


on
Google+
Quick Navigation Visual Basic .NET Top

Previous Thread | Next Thread

VBForums Visual Basic Visual Basic .NET [RESOLVED] Tableadapter Update Command only works once!?@

Posting Permissions
You may not post new threads BB code is On
You may not post replies Smilies are On
You may not post attachments [IMG] code is On
You may not edit your posts [VIDEO] code is On
HTML code is Off
Forum Rules

Contact Us VB Forums Top

Acceptable Use Policy

Property of Quinstreet Enterprise.


Terms of Service | Licensing & Reprints | Privacy Policy | Advertise

http://www.vbforums.com/showthread.php?516858-RESOLVED-Tableadapter-Update-Command-only-works-once! 4/5
7/3/2016 [RESOLVED] Tableadapter Update Command only works once!?@-VBForums
Copyright 2016 QuinStreet Inc. All Rights Reserved.
All times are GMT -5. The time now is 11:53 PM.

http://www.vbforums.com/showthread.php?516858-RESOLVED-Tableadapter-Update-Command-only-works-once! 5/5

Vous aimerez peut-être aussi