TableAdapter.Update(tableName); does not update table

I am new to connecting to an Access database via the multitude of automated tools provided by Visual Studio 2005, but find that my call to Update() does not work.  I cal the Update() method inside the updateBtn_Click() handler, on the last line.

I will post the entire partial class here:

namespace WindowsApplication1
{
    partial class Form1
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.components = new System.ComponentModel.Container();
            this.dMS_HaughtonDataSet = new WindowsApplication1.DMS_HaughtonDataSet();
            this.fillByToolStrip = new System.Windows.Forms.ToolStrip();
            this.fillByToolStripButton = new System.Windows.Forms.ToolStripButton();
            this.badgeIDsBindingSource = new System.Windows.Forms.BindingSource(this.components);
            this.badgeIDsTableAdapter = new WindowsApplication1.DMS_HaughtonDataSetTableAdapters.BadgeIDsTableAdapter();
            this.updateBtn = new System.Windows.Forms.Button();
            this.dataGridView1 = new System.Windows.Forms.DataGridView();
            this.iDDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.wirelessIDDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.badgeIDDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.restaurantIDDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.physicalDescriptionDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
            ((System.ComponentModel.ISupportInitialize)(this.dMS_HaughtonDataSet)).BeginInit();
            this.fillByToolStrip.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.badgeIDsBindingSource)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
            this.SuspendLayout();
            //
            //
            // dMS_HaughtonDataSet
            //
            this.dMS_HaughtonDataSet.DataSetName = "DMS_HaughtonDataSet";
            this.dMS_HaughtonDataSet.SchemaSerializationMode = System.Data.SchemaSerializationMode.IncludeSchema;
            //
            // fillByToolStrip
            //
            this.fillByToolStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.fillByToolStripButton});
            this.fillByToolStrip.Location = new System.Drawing.Point(0, 0);
            this.fillByToolStrip.Name = "fillByToolStrip";
            this.fillByToolStrip.Size = new System.Drawing.Size(292, 25);
            this.fillByToolStrip.TabIndex = 1;
            this.fillByToolStrip.Text = "fillByToolStrip";
            //
            // fillByToolStripButton
            //
            this.fillByToolStripButton.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text;
            this.fillByToolStripButton.Name = "fillByToolStripButton";
            this.fillByToolStripButton.Size = new System.Drawing.Size(35, 22);
            this.fillByToolStripButton.Text = "FillBy";
            this.fillByToolStripButton.Click += new System.EventHandler(this.fillByToolStripButton_Click);
            //
            // badgeIDsBindingSource
            //
            this.badgeIDsBindingSource.DataMember = "BadgeIDs";
            this.badgeIDsBindingSource.DataSource = this.dMS_HaughtonDataSet;
            //
            // badgeIDsTableAdapter
            //
            this.badgeIDsTableAdapter.ClearBeforeFill = true;
            //
            // updateBtn
            //
            this.updateBtn.Location = new System.Drawing.Point(94, 221);
            this.updateBtn.Name = "updateBtn";
            this.updateBtn.Size = new System.Drawing.Size(75, 23);
            this.updateBtn.TabIndex = 2;
            this.updateBtn.Text = "Update";
            this.updateBtn.UseVisualStyleBackColor = true;
            this.updateBtn.Click += new System.EventHandler(this.updateBtn_Click);
            //
            // dataGridView1
            //
            this.dataGridView1.AutoGenerateColumns = false;
            this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
            this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
            this.iDDataGridViewTextBoxColumn,
            this.wirelessIDDataGridViewTextBoxColumn,
            this.badgeIDDataGridViewTextBoxColumn,
            this.restaurantIDDataGridViewTextBoxColumn,
            this.physicalDescriptionDataGridViewTextBoxColumn});
            this.dataGridView1.DataSource = this.badgeIDsBindingSource;
            this.dataGridView1.Location = new System.Drawing.Point(34, 44);
            this.dataGridView1.Name = "dataGridView1";
            this.dataGridView1.Size = new System.Drawing.Size(240, 150);
            this.dataGridView1.TabIndex = 3;
            //
            // iDDataGridViewTextBoxColumn
            //
            this.iDDataGridViewTextBoxColumn.DataPropertyName = "ID";
            this.iDDataGridViewTextBoxColumn.HeaderText = "ID";
            this.iDDataGridViewTextBoxColumn.Name = "iDDataGridViewTextBoxColumn";
            //
            // wirelessIDDataGridViewTextBoxColumn
            //
            this.wirelessIDDataGridViewTextBoxColumn.DataPropertyName = "WirelessID";
            this.wirelessIDDataGridViewTextBoxColumn.HeaderText = "WirelessID";
            this.wirelessIDDataGridViewTextBoxColumn.Name = "wirelessIDDataGridViewTextBoxColumn";
            //
            // badgeIDDataGridViewTextBoxColumn
            //
            this.badgeIDDataGridViewTextBoxColumn.DataPropertyName = "BadgeID";
            this.badgeIDDataGridViewTextBoxColumn.HeaderText = "BadgeID";
            this.badgeIDDataGridViewTextBoxColumn.Name = "badgeIDDataGridViewTextBoxColumn";
            //
            // restaurantIDDataGridViewTextBoxColumn
            //
            this.restaurantIDDataGridViewTextBoxColumn.DataPropertyName = "RestaurantID";
            this.restaurantIDDataGridViewTextBoxColumn.HeaderText = "RestaurantID";
            this.restaurantIDDataGridViewTextBoxColumn.Name = "restaurantIDDataGridViewTextBoxColumn";
            //
            // physicalDescriptionDataGridViewTextBoxColumn
            //
            this.physicalDescriptionDataGridViewTextBoxColumn.DataPropertyName = "PhysicalDescription";
            this.physicalDescriptionDataGridViewTextBoxColumn.HeaderText = "PhysicalDescription";
            this.physicalDescriptionDataGridViewTextBoxColumn.Name = "physicalDescriptionDataGridViewTextBoxColumn";
            //
            // Form1
            //
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(292, 266);
            this.Controls.Add(this.dataGridView1);
            this.Controls.Add(this.updateBtn);
            this.Controls.Add(this.fillByToolStrip);
            this.Name = "Form1";
            this.Text = "Form1";
            this.Load += new System.EventHandler(this.Form1_Load);
            ((System.ComponentModel.ISupportInitialize)(this.dMS_HaughtonDataSet)).EndInit();
            this.fillByToolStrip.ResumeLayout(false);
            this.fillByToolStrip.PerformLayout();
            ((System.ComponentModel.ISupportInitialize)(this.badgeIDsBindingSource)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion

        private DMS_HaughtonDataSet dMS_HaughtonDataSet;
        private System.Windows.Forms.BindingSource badgeIDsBindingSource;
        private WindowsApplication1.DMS_HaughtonDataSetTableAdapters.BadgeIDsTableAdapter badgeIDsTableAdapter;
        private System.Windows.Forms.ToolStrip fillByToolStrip;
        private System.Windows.Forms.ToolStripButton fillByToolStripButton;
        private System.Windows.Forms.Button updateBtn;
        private System.Windows.Forms.DataGridView dataGridView1;
        private System.Windows.Forms.DataGridViewTextBoxColumn iDDataGridViewTextBoxColumn;
        private System.Windows.Forms.DataGridViewTextBoxColumn wirelessIDDataGridViewTextBoxColumn;
        private System.Windows.Forms.DataGridViewTextBoxColumn badgeIDDataGridViewTextBoxColumn;
        private System.Windows.Forms.DataGridViewTextBoxColumn restaurantIDDataGridViewTextBoxColumn;
        private System.Windows.Forms.DataGridViewTextBoxColumn physicalDescriptionDataGridViewTextBoxColumn;
    }
}

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'dMS_HaughtonDataSet.BadgeIDs' table. You can move, or remove it, as needed.
            this.badgeIDsTableAdapter.Fill(this.dMS_HaughtonDataSet.BadgeIDs);

        }

        private void fillByToolStripButton_Click(object sender, EventArgs e)
        {
            try
            {
                //this.batchProcessesTableAdapter.FillBy(this.dMS_HaughtonDataSet.BadgeIDs);
            }
            catch (System.Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);
            }

        }

        private void updateBtn_Click(object sender, EventArgs e)
        {
            badgeIDsTableAdapter.Update(this.dMS_HaughtonDataSet.BadgeIDs);
        }
    }
}
newbiewebSr. Software EngineerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SameerJagdaleCommented:
are you getting any error? if yes please post it.. before update ..can you check the tables count..something like:
private void updateBtn_Click(object sender, EventArgs e)
        {
            int count = this.dMS_HaughtonDataSet.Tables.Count;
            badgeIDsTableAdapter.Update(this.dMS_HaughtonDataSet.BadgeIDs);
        }
 
0
Priest04Commented:
In theupdateBtn_Click event, add this code

private void updateBtn_Click(object sender, EventArgs e)
{
    DataTable dtTemp = this.dMS_HaughtonDataSet.BadgeIDs.GetChanges();
    if (dtTemp == null) MessageBox.Show("No data changed!");
    badgeIDsTableAdapter.Update(this.dMS_HaughtonDataSet.BadgeIDs);
}

Goran
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
newbiewebSr. Software EngineerAuthor Commented:
OK.

I added the code each of you had suggested, and the # of  tables is 44.  And the message box only opens when I have made changes.  

I am using an Access database.  But when I had Access open and made changes I got  this exception:

{"Concurrency violation: the UpdateCommand affected 0 of the expected 1 records."}

Then I closed Access and no  longer got an error when I called Update(), but the update did not happen.  I opened Access and found the old value in the database.  Any ideas?

newbieweb

I am using an Access database.
0
Build an E-Commerce Site with Angular 5

Learn how to build an E-Commerce site with Angular 5, a JavaScript framework used by developers to build web, desktop, and mobile applications.

Priest04Commented:
lets see if anything is wrong with the InsertCommand, UpdateCommand or DeleteCommand. Try this

private void updateBtn_Click(object sender, EventArgs e)
{
    OleDbCommandBuilder cmb = new OleDbCommandBuilder(badgeIDsTableAdapter); \\ this will recreate all command objects
    badgeIDsTableAdapter.Update(this.dMS_HaughtonDataSet.BadgeIDs);
}
0
newbiewebSr. Software EngineerAuthor Commented:
I'm getting a compilation error here:

OleDbCommandBuilder cmb = new OleDbCommandBuilder(badgeIDsTableAdapter);

I wants an OleDataAdapter not a:

WindowsApplication1.DMS_HaughtonDataSetTableAdapters.BadgeIDsTableAdapter
0
Priest04Commented:
Ah, you are using a tableAdapter, sorry. Two things:

1) have you changed tables structure in a database after you have created dataset through designer?
2) do you have a primary key set for table?
0
newbiewebSr. Software EngineerAuthor Commented:
1)  No I have not changed the database structure.
2) In Access, I had definned the ID column as AutoIncrement and selected it as the Key, so there is an icon of a Key next  to it.
0
Priest04Commented:
I dont see what else could be the cause here. Can you rebuild table adapter just to make sure its compatible with database structure?
0
newbiewebSr. Software EngineerAuthor Commented:
How do I rebuild it?  I used the drag and drop features of Visual Studio 2005.  

I think I will start  with a new application and see if  that  works .

thanks,
newbieweb
0
newbiewebSr. Software EngineerAuthor Commented:
It's working  now.

I rebuilt the tiny project and the update worked.  This time I chose not to add the local database to the project.

Thanks,
newbieweb
0
Priest04Commented:
>> This time I chose not to add the local database to the project.

If you choosed to add database to the project directory, then it copies your database (ex. c:\Test.mdb) to your projects directory (ex. c:\MyProject\test.mdb).

In this case, c:\test.mdb will always contain old data, and new data will be in c:\MyProject\test.mdb database.

That is all that has to do with adding database to the project.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.