|
-
Jul 18th, 2003, 09:48 AM
#1
Thread Starter
Fanatic Member
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());
}
}
-
Jul 18th, 2003, 10:20 AM
#2
Frenzied Member
-
Jul 18th, 2003, 09:17 PM
#3
Sleep mode
What don't you use Update Command if possible ??
-
Jul 19th, 2003, 11:00 AM
#4
Thread Starter
Fanatic Member
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
-
Jul 19th, 2003, 11:56 AM
#5
Sleep mode
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|