Solved

TableAdapter.Update(tableName); does not update table

Posted on 2008-10-04
11
1,399 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
[X]
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
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

617 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