Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. TableAdapter.Update will not save my data

TableAdapter.Update will not save my data

Scheduled Pinned Locked Moved C#
helpquestionannouncement
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Christopher Thornburg
    wrote on last edited by
    #1

    Okay I can't get my update to work. here is my code: namespace DBWinVoice { public partial class Company : Form { WinVoiceDataSet companyDS = new WinVoiceDataSet(); public Company() { InitializeComponent(); } private void Company_Load(object sender, EventArgs e) { // TODO: This line of code loads data into the 'winVoiceDataSet.Company' table. You can move, or remove it, as needed. this.companyTableAdapter.Fill(this.winVoiceDataSet.Company); } private void button1_Click(object sender, EventArgs e) { try { this.companyBindingSource.EndEdit(); this.companyTableAdapter.Update(this.companyDS); MessageBox.Show("Update Successful"); } catch (System.Exception ex) { MessageBox.Show(ex.ToString()); } } } } I know I am doing something dumb...can anyone help me? Thanks

    Christopher J. Thornburg Senior Systems Analyst Ideal Card

    D 1 Reply Last reply
    0
    • C Christopher Thornburg

      Okay I can't get my update to work. here is my code: namespace DBWinVoice { public partial class Company : Form { WinVoiceDataSet companyDS = new WinVoiceDataSet(); public Company() { InitializeComponent(); } private void Company_Load(object sender, EventArgs e) { // TODO: This line of code loads data into the 'winVoiceDataSet.Company' table. You can move, or remove it, as needed. this.companyTableAdapter.Fill(this.winVoiceDataSet.Company); } private void button1_Click(object sender, EventArgs e) { try { this.companyBindingSource.EndEdit(); this.companyTableAdapter.Update(this.companyDS); MessageBox.Show("Update Successful"); } catch (System.Exception ex) { MessageBox.Show(ex.ToString()); } } } } I know I am doing something dumb...can anyone help me? Thanks

      Christopher J. Thornburg Senior Systems Analyst Ideal Card

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      What are the error messages, if any?? Define how it's "not working". Does this table have a primary key that is returned by the SELECT statement?? The adapters won't work without it. The Adapters write the changes back to the database by executing the INSERT, DELETE, and UPDATE command for each line in the table that needs updating. Without a primary key in your table, AND without that key being part of the resulting recordset, there is no way for the TableAdapter to tell the SQL database which record to update and how to do it.

      A guide to posting questions on CodeProject[^]
      Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
           2006, 2007

      C 1 Reply Last reply
      0
      • D Dave Kreskowiak

        What are the error messages, if any?? Define how it's "not working". Does this table have a primary key that is returned by the SELECT statement?? The adapters won't work without it. The Adapters write the changes back to the database by executing the INSERT, DELETE, and UPDATE command for each line in the table that needs updating. Without a primary key in your table, AND without that key being part of the resulting recordset, there is no way for the TableAdapter to tell the SQL database which record to update and how to do it.

        A guide to posting questions on CodeProject[^]
        Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
             2006, 2007

        C Offline
        C Offline
        Christopher Thornburg
        wrote on last edited by
        #3

        Yes I have a primary key. I am not getting any error messages it just will not work. I have just added tables to my dataset so I need to change my code a bit. Would this work better if I used a datatable variable assigned my company table and then passed the datatable to the update or should I use datarows????? I just want you to know I have no idea what I am doing....:) I am a little confused about the whole thing.

        Christopher J. Thornburg

        J 1 Reply Last reply
        0
        • C Christopher Thornburg

          Yes I have a primary key. I am not getting any error messages it just will not work. I have just added tables to my dataset so I need to change my code a bit. Would this work better if I used a datatable variable assigned my company table and then passed the datatable to the update or should I use datarows????? I just want you to know I have no idea what I am doing....:) I am a little confused about the whole thing.

          Christopher J. Thornburg

          J Offline
          J Offline
          Jpuckett
          wrote on last edited by
          #4

          You're passing an empty DataSet to the update method. You intialize companyDS as new and then never assign any data to it. That's why there is no error. It is successfully updating with an empty DataSet into a database (that presumably) allows NULL values or empty strings.

          C 1 Reply Last reply
          0
          • J Jpuckett

            You're passing an empty DataSet to the update method. You intialize companyDS as new and then never assign any data to it. That's why there is no error. It is successfully updating with an empty DataSet into a database (that presumably) allows NULL values or empty strings.

            C Offline
            C Offline
            Christopher Thornburg
            wrote on last edited by
            #5

            Okay cool...will you show me how to do it???? I think I would need a dataset.table variable and then assign it the data of the current row, and then pass that to the tableadapter.update() is this right? can you show me how you would do it in some code. I have 4 tables in my dataset. Dataset = WinVoiceDataSet Table = Company

            Christopher J. Thornburg

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups