Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

TableAdapter.Update(tableName); does not update table

Posted on 2008-10-04
11
1,377 Views
Last Modified: 2013-12-17
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);
        }
    }
}
0
Comment
Question by:newbieweb
  • 5
  • 5
11 Comments
 
LVL 13

Assisted Solution

by:SameerJagdale
SameerJagdale earned 200 total points
ID: 22644095
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
 
LVL 18

Accepted Solution

by:
Priest04 earned 300 total points
ID: 22644115
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
 

Author Comment

by:newbieweb
ID: 22644645
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
Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

 
LVL 18

Expert Comment

by:Priest04
ID: 22644769
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
 

Author Comment

by:newbieweb
ID: 22644814
I'm getting a compilation error here:

OleDbCommandBuilder cmb = new OleDbCommandBuilder(badgeIDsTableAdapter);

I wants an OleDataAdapter not a:

WindowsApplication1.DMS_HaughtonDataSetTableAdapters.BadgeIDsTableAdapter
0
 
LVL 18

Expert Comment

by:Priest04
ID: 22644985
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
 

Author Comment

by:newbieweb
ID: 22645042
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
 
LVL 18

Expert Comment

by:Priest04
ID: 22645068
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
 

Author Comment

by:newbieweb
ID: 22645089
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
 

Author Comment

by:newbieweb
ID: 22645120
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
 
LVL 18

Expert Comment

by:Priest04
ID: 22645160
>> 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

Featured Post

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question