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()); } }




Reply With Quote