tableadapter.update

btran007

Member
Joined
Aug 16, 2006
Messages
19
Programming Experience
Beginner
Hello All,
I am trying to update two fields based on where chart = @chart. Update executed successfully but nothing happens. Where or at what point does it ask for @chart value. I even tried to create another update function but the program just removes it by itself. I am confused...please help.

thanks
btran

Me._adapter.UpdateCommand.CommandText = "UPDATE Chart SET Release = 1, ReleaseDate = Now() WHERE Chart = @chart)
---------
Me.ChartTableAdapter.Update(Me.DataSet1.Chart)
----------
<System.Diagnostics.DebuggerNonUserCodeAttribute(), System.ComponentModel.Design.HelpKeywordAttribute "vs.data.TableAdapter")>
Public Overloads Overridable Function Update(ByVal chart As String) As Integer
me.Adapter.UpdateCommand.Parameters(0).Value = chart
return me.Adapter.UpdateCommand.ExecuteNonQuery()
End Function
 

cjard

Well-known member
Joined
Apr 25, 2006
Messages
7,052
Programming Experience
10+
Me._adapter.UpdateCommand.CommandText = "UPDATE Chart SET Release = 1, ReleaseDate = Now() WHERE Chart = @chart)
Erm. Unless youre editing the table adapter code (which you shouldnt do), you wouldnt do this, or Me._adapter refers to an object that is not the tableadapter

---------
Me.ChartTableAdapter.Update(Me.DataSet1.Chart)
----------
Again, this kinda doesnt make sense. I recommend posting more code from your project, or reading the DW2 link in my signature, section on saving data


<System.Diagnostics.DebuggerNonUserCodeAttribute(), System.ComponentModel.Design.HelpKeywordAttribute "vs.data.TableAdapter")>
Public Overloads Overridable Function Update(ByVal chart As String) As Integer
me.Adapter.UpdateCommand.Parameters(0).Value = chart
return me.Adapter.UpdateCommand.ExecuteNonQuery()
End Function

Okay, but that is the overload that takes a string argument. It isnt going to be called if you supply a DataTable argument..

Read the DW2 link; it will be very enlightening as to how you should do your data access
 

btran007

Member
Joined
Aug 16, 2006
Messages
19
Programming Experience
Beginner
cjard

Thank you for your comments. I got it to work using the overload function. However, the overload function can be erased automatically by VS. I only got it to work if it's created and build immediately without moving around in the project. I don't know why it's being removed if I click on another page.

Me._adapter I got from the Designer.vb to show the query with one parameter. And I did read the Data Walkthrough but I wasn't able to get it work. That's where you come in.

Thanks
btran
 

cjard

Well-known member
Joined
Apr 25, 2006
Messages
7,052
Programming Experience
10+
:)
And I did read the Data Walkthrough but I wasn't able to get it work.

So, youre telling me that you followed a list of instructions, written in good clear plain english, by the people who created .NET and have been followed by thousands of other people all around the world without a problem (trust me; tens of them have come back here and thanked me for pointing them in the right direction)... And I'm supposed to know what you did wrong? :confused::confused:

How about you go back and follow them again, and I mean exactly. If it says "Download the same Northwind database" then go and download the sample northwind database! If it says stroke the right hand side of the monitor, then stroke the right hand side of the monitor! :)

See that attribute in the tableadapter code.. "DebuggerNonUserCodeAttribute" - non user code means you didnt write it, and shouldnt be poking around in it. The comment at the top saying "this file is automatically generated. Edits will be lost if this file is regenerated" - that means DONT MESS! Whatever you want to do, you can do WITHOUT messing in that file!
Threre really arent thousands of confused newbies out there in the world, messing with files that they shouldnt be messing in, and cursing Microsoft for making things hard (i.e. youre the only one not doing things as Microsoft designed, and hence the only one having problems)

Start on the right path, dump the code you've written, go back to the tutorials and follow them through. Once you have done them, and youre happy with the way they work, go back to your own project and start it over with the new methods. Once you know what youre doing, you'll need about 10 minutes to get a form that reads and writes database data

Also, read the DNU link for a common trap newbies fall into.
 
Top Bottom