Can't update TableAdapter

johncassell

Well-known member
Joined
Jun 10, 2007
Messages
120
Location
Redcar, England
Programming Experience
Beginner
Hello,

can someone help me with this please...

I had a project where I could update the TableAdapter no problem..
VB.NET:
Private Sub Save_Job_Bttn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Save_Job_Bttn.Click
        Me.Validate()
        Me.JobsBindingSource.EndEdit()
        Me.JobsTableAdapter.Update(Me.RedcarWorkshopDataSet.Jobs)
    End Sub

But in my new project using Visual Studio when I type the equivalent of " Me.JobsTableAdapter. " it brings up the usual list of items to choose from but update is not there. Is there a setting somewhere which I am not aware of.

Any help at all would be really appreciated.

Thanks

John
 
Hi Again,

Typical, I try and work it out on my own until I give in and as soon as I post the question here, I figure it out! :)

Anyway, for those interested..

The reason I didn't have the update option was because my TableAdapter in the dataset.xsd had the update command set to none in the properties window.

Thanks anyway.

John
 
Hello,

can someone help me with this please...

I had a project where I could update the TableAdapter
You dont update tableadapters. Update() is a method of tableadapter that causes changes to a datatable to be persisted back to its relevant database table


But in my new project using Visual Studio when I type the equivalent of " Me.JobsTableAdapter. " it brings up the usual list of items to choose from but update is not there. Is there a setting somewhere which I am not aware of.
What DOES it come up with?

Either your tableadapter has no database updating methods (no INS, UPD or DEL queries) or youre mistakenly calling it on the TYPE, not an instance
 
The reason I didn't have the update option was because my TableAdapter in the dataset.xsd had the update command set to none in the properties window.

A table adapter with no UPDATE sql, but with an INSERT and/or DELETE sqls will still have a Update() command

Update() is nothing to do with the UPDATE sql

Update() should be called PersistToDB() or something, the confusion it causes
 
Hi cjard, on that note I am also struggling to update my TableAdapter.

I have a dataset represented by "dataset.gif" (attached) with a simple form (for test purposes) and a few controls for input.

but I get an error that I dont quite understand. attached is the declarations image as well as the code-with-error image.

I have read your data walkthroughs as well as many others, but I think I need more to understand where I have gone wrong.

what would you recommend I do?
 

Attachments

  • dataset.gif
    dataset.gif
    3 KB · Views: 30
  • code.gif
    code.gif
    17.2 KB · Views: 33
  • declare.gif
    declare.gif
    3.5 KB · Views: 29
mind you, my code was no cleaner, but I was doing the following to add a new row via code;

VB.NET:
Dim tblRev As DataTable = Me.DsDevelopment.Tables("Revision")
Dim DR As DataRow = tblRev.NewRow()
DR("MyID") = Me.lblTSDWR.Text
DR("RevisionNo") = 1
DR("RevisionDate") = me.dtpRevDate.text
tblRev.Rows.Add(DR)
'rest of my code here
...
...
me.RevisionTableAdapter.Update(me.dataSet1, Revision)
 
Hi Arg81,

yeah, i agree with your first statement...code aint pretty. Could u point me in the direction of a tutorial I could follow in this regard.

The other method I have chosen to perhaps implement is to use an SQL Insert Query that I created in the TableAdapter in the dataset designer. Is there a more preferred method to this? I mean what is the difference between using an SQL Insert Query or using the TableAdapter.Update approach?
 
but I get an error that I dont quite understand. attached is the declarations image as well as the code-with-error image.

The error message simply means that you havent created an instance of DTtest

In your declare gif, you say DTtest is of type testingDataTable, but you dont ever make a New object instance!


What is of more concern to me is that you have set up a dataset and table adapter, but your manually shoving data in and out of it.. I cant quite see why. Do you dislike bound controls?
I expected that your controls would all be bound, your tableadapter, dataset adn bindingsources would be made by the IDE as part of the designer generated code to the form, and that's it!

As such, your new row code would look more like:

VB.NET:
  myBindingSource.AddNew()
Typically the user would then set the values AFTER you call addnew

If you really want them set before, then you can maybe do this to neaten things up a bit:

myDs.testingDataTable.t_idColumn.DefaultValue = 1
myDs.testingDataTable.t_nameColumn.DefaultValue = TextBox1.Text
myBS.AddNew()
myBS.EndEdit()
myTA.Update(myDS.testingDataTable)
 
mind you, my code was no cleaner, but I was doing the following to add a new row via code;
And that's a wee bit ugly too! Cmon.. Typed Datasets. Let's get it right:

VB.NET:
Dim dr As [B]DsDevelopment.Revision[/B]Row = [B]Me.DsDevelopment.RevisionDataTable.[/B]New[B]Revision[/B]Row()
[B]dr.MyID[/B] = Me.lblTSDWR.Text
[B]dr.RevisionNo [/B]= 1
[B]dr.RevisionDate[/B] = me.dtpRevDate.text 'ugly ugly! DO NOT set or store dates as text! never ever! is 12/06/2006 the 6th of dec or the 12th of june?
'revision date column should have a data type of DATE, and in the db it should be a DATE, and you should set it with dtp.Value! Slap slap! :)
[B]Me.DsDevelopment.RevisionDataTable.AddRevisionRow(dr)[/B]

'rest of my code here
...
...
me.RevisionTableAdapter.Update([B]Me.DsDevelopment.RevisionDataTable[/B])
 
urm, yeah, it is set to .value {cough} , I wrote .text as I was quickly writing it out {double cough} Although truefully it is set as date in my DB and dataTable.

Actually, I set the dtp value to copy to a label text. I then bind the label to the data.

I tell you why the dataset is the way I wrote it - this was an upgraded project from VS2003. some bits I just never got round to tidying up - that was one of them - thanks for letting me know what I need to change it too!!
 
Last edited:

Latest posts

Back
Top