Results 1 to 5 of 5

Thread: Problems with OleDb updating

  1. #1

    Thread Starter
    Fanatic Member Bombdrop's Avatar
    Join Date
    Apr 2001
    Location
    St Helens, England, UK
    Posts
    667

    Problems with OleDb updating

    Can any one please help me out, how come this does not update my dataBases it riases an exception, please plase help a VB6 refugee
    Code:
    using System;
    using System.Drawing;
    using System.Windows.Forms;
    using System.Data;
    using SQL= System.Data.OleDb;
    
    namespace OleDbTest 
    {
    	class MainForm : System.Windows.Forms.Form
    	{
    		private System.Windows.Forms.TreeView treeView;
    		private System.Windows.Forms.ListBox listBox;
    		private System.Windows.Forms.Button button;
    		
    		public MainForm()
    		{
    			InitializeComponent();
    		}
    	
    		// This method is used in the forms designer.
    		// Change this method on you own risk
    		void buttonClick(object sender, System.EventArgs e)
    		{
    			this.treeView.Nodes.Clear();
    			//Set up the connection
    			SQL.OleDbConnection oCon = new SQL.OleDbConnection("file Name = c:\\test.udl");
    			
    			//Set up the command
    			SQL.OleDbCommand oCmd = new SQL.OleDbCommand("select * from People",oCon);
    			
    			//Open the connection
    			//oCon.Open();
    			
    			//Set up a DatAdapter  filling it with a command
    			SQL.OleDbDataAdapter oAdp = new SQL.OleDbDataAdapter(oCmd);
    			
    			//Create a DataSet Object
    			DataSet oData = new DataSet();
    			
    			//Fill the DataSet With information from the 
    			//DataAdapter.
    			oAdp.Fill(oData,"People");
    			
    			//Create a Table object and fill it from the 
    			//DataSet Object.
    			DataTable oTable = oData.Tables[0];
    			
    		
    			//Creat a TreeNodeObject  and set its Text
    			TreeNode oNode= new TreeNode("People");
    			
    			try{
    			//Traverse the table object Row and fill a listbox
    			 
    			foreach(DataRow oRow in oTable.Rows)
    			{
    				//Add the names to listbox
    				this.listBox.Items.Add(oRow [1] );
    				//Add the names to the Node object
    				oNode.Nodes.Add(oRow[1].ToString());
    
    			}
    			
    			//Add the Node OBject to the Treeview
    			this.treeView.Nodes.Add(oNode);
    				
    				DataRow oRow1 = oTable.Rows[3];
    				oRow1.BeginEdit();
    				oRow1[1]="Sod off";
    				oRow1.EndEdit();
    				
    				
    			DataSet oChanges = oData.GetChanges(DataRowState.Modified);
    				if (oChanges.HasErrors)
    				{
    					MessageBox.Show("ERRORS In GET MOD")	;
    				}
    				else{
    					MessageBox.Show(" NO ERRORS In GET MOD");
    				}
    			oData.Merge(oChanges);
    				
    			oAdp.Update(oChanges);//.Update(oData,"People");
    				
    			}//End Try
    			
    				catch( Exception ex)
    				{
    					MessageBox.Show(ex.ToString());
    				}
    			
    		}

  2. #2
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    What is the error?

  3. #3
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    What don't you use Update Command if possible ??

  4. #4

    Thread Starter
    Fanatic Member Bombdrop's Avatar
    Join Date
    Apr 2001
    Location
    St Helens, England, UK
    Posts
    667
    System.InvalidOperationException: Update unable to find TableMapping['Table'] or DataTable 'Table'.
    at System.Data.Common.DbDataAdapter.Update(DataSet dataSet, String srcTable)
    at System.Data.Common.DbDataAdapter.Update(DataSet dataSet)
    at OleDbTest.MainForm.buttonClick(Object sender, EventArgs e) in C:\Documents and Settings\Administrator\My Documents\SharpDevelop Projects\DataBase\MainForm.cs:line 101
    Above is the exception messgae I get when i try to updat my my DB via the update method of the DataAdapter

  5. #5
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    How many tables have you got in your db ? It's maybe you are referring to a table that's not exist in the dataset . I can't tell though

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width