Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Express Edition and Compact Edition (2005)
 SEVER EXPRESS TABLE MAPPING EXCEPTION!!!

Author  Topic 

markyjj
Starting Member

8 Posts

Posted - 2008-08-24 : 12:10:47
Can someone please help me with the following problem because I am now at my witts end with this program. I am trying to update a server express Sql database through a datgrid through a custom 'Save & Update button' but I get the following exception

' Update unable to find TableMapping['MovTable1'] or DataTable 'MovTable1'.

I have tried creating a command builder and a Table map but I still get the same exception and I am now in need of help. The code I am using is below. Many thanks



//Main Form
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;


namespace MovieBase1
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button3;
private System.Windows.Forms.Button button4;
private System.Windows.Forms.Button button5;
private System.Windows.Forms.Button button6;
private System.Windows.Forms.Label label1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;

public DataSet Movset1 = new DataSet();




public static SqlConnection Mcon = new SqlConnection("workstation id=SHERMAN2;packet size=4096;integrated security=SSPI;data source=\"SH" +
"ERMAN2\\SQLEXPRESS\";persist security info=True;initial catalog=MDatabase");

public SqlCommand Movcmd = Mcon.CreateCommand();
private System.Windows.Forms.Button button7;

public SqlDataAdapter MovAdapt = new SqlDataAdapter();







public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (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.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
this.button4 = new System.Windows.Forms.Button();
this.button5 = new System.Windows.Forms.Button();
this.button6 = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.button7 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(304, 72);
this.button1.Name = "button1";
this.button1.TabIndex = 0;
this.button1.Text = "Delete Film";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(328, 120);
this.button2.Name = "button2";
this.button2.TabIndex = 1;
this.button2.Text = "Current Movie Count";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// button3
//
this.button3.Location = new System.Drawing.Point(336, 168);
this.button3.Name = "button3";
this.button3.TabIndex = 2;
this.button3.Text = "Movie List";
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// button4
//
this.button4.Location = new System.Drawing.Point(336, 208);
this.button4.Name = "button4";
this.button4.TabIndex = 3;
this.button4.Text = "Exit";
this.button4.Click += new System.EventHandler(this.button4_Click);
//
// button5
//
this.button5.Location = new System.Drawing.Point(336, 264);
this.button5.Name = "button5";
this.button5.TabIndex = 4;
this.button5.Text = "button5";
this.button5.Click += new System.EventHandler(this.button5_Click);
//
// button6
//
this.button6.Location = new System.Drawing.Point(328, 16);
this.button6.Name = "button6";
this.button6.TabIndex = 5;
this.button6.Text = "Add Film";
this.button6.Click += new System.EventHandler(this.button6_Click);
//
// label1
//
this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.label1.Location = new System.Drawing.Point(32, 16);
this.label1.Name = "label1";
this.label1.TabIndex = 6;
this.label1.Text = "Movie Base";
//
// button7
//
this.button7.Location = new System.Drawing.Point(80, 152);
this.button7.Name = "button7";
this.button7.Size = new System.Drawing.Size(168, 23);
this.button7.TabIndex = 7;
this.button7.Text = "button7";
this.button7.Click += new System.EventHandler(this.button7_Click);
//
// Form1
//
this.AccessibleDescription = "public";
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(432, 366);
this.Controls.Add(this.button7);
this.Controls.Add(this.label1);
this.Controls.Add(this.button6);
this.Controls.Add(this.button5);
this.Controls.Add(this.button4);
this.Controls.Add(this.button3);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());

}

private void button6_Click(object sender, System.EventArgs e)
{

MessageBox.Show("under construction");
}

private void button1_Click(object sender, System.EventArgs e)
{
MessageBox.Show("under construction");
}

private void button2_Click(object sender, System.EventArgs e)
{
MessageBox.Show(" under constructiion ");
}

private void button3_Click(object sender, System.EventArgs e)
{ Form3 F3 = new Form3();
Mcon.Open();
SqlCommandBuilder cmdBuilder = new SqlCommandBuilder(MovAdapt);
Movcmd.CommandText = "SELECT * FROM MovTable1";
MovAdapt.SelectCommand = Movcmd;
MovAdapt.Fill(Movset1, "MovTable1");
F3.dataGrid1.DataSource = Movset1;
F3.Show();
}

private void button4_Click(object sender, System.EventArgs e)
{
this.Close();
}

private void button5_Click(object sender, System.EventArgs e)
{
MessageBox.Show("under construction");
}

private void button7_Click(object sender, System.EventArgs e)
{

}


}
}


---------------------
//2nd form with Save & Update button
DataTable MovTable1 = new DataTable();
F1.Movset1.Tables.Add(MovTable1);
F1.MovAdapt.TableMappings.Add( "Table", "MovTable1" );
F1.MovAdapt.Update(F1.Movset1,"MovTable1");
Form1.Mcon.Close();
   

- Advertisement -