|
|
|
Re: Filling a Dataset from an Oracle 10g Database
Started by daz4805 at 01-06-2006 12:54 PM. Topic has 1 replies.
|
|
01-06-2006, 12:54 PM
|
daz4805
Joined on 01-06-2006
Posts 3
|
Filling a Dataset from an Oracle 10g Database
|
|
|
|
|
Hi, I am new at C# programming and I have a problem with a project that i am coding.
I have run the Dataform Wizzard and this has generated the following code (i have removed bits and pieces from this as i didnt think it was needed to be pasted): -
using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; using System.Data.Odbc; using System.Data.OleDb; using System.IO; using Microsoft.CSharp; using System.Diagnostics; using System.Data.OracleClient; using Oracle.DataAccess;
namespace Timesheet { /// /// /// Summary description for Task_Maintenance?. /// public class Task_Maintenance? : System.Windows.Forms.Form { OracleConnection? localcon; private System.Data.OracleClient.OracleCommand oleDbInsertCommand1; private System.Data.OracleClient.OracleCommand oleDbUpdateCommand1; private System.Data.OracleClient.OracleCommand oleDbDeleteCommand1; //private System.Data.OracleClient.OracleConnection.Equals localcon; private System.Data.OracleClient.OracleDataAdapter oleDbDataAdapter1; private Timesheet.TaskMaintenance objTaskMaintenance; private System.Windows.Forms.Button btnLoad; private System.Windows.Forms.Button btnUpdate; private System.Windows.Forms.Button btnCancelAll; private System.Windows.Forms.DataGrid grdTASK; private System.Data.OracleClient.OracleCommand oleDbCommand1; /// /// Required designer variable. /// private System.ComponentModel.Container components = null; public Task_Maintenance() { // // Required for Windows Form Designer support // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent? call // }
/// /// Clean up any resources being used. /// protected override void Dispose( bool disposing ) { if( disposing ) { if(components != null) { components.Dispose(); } } base.Dispose( disposing ); } public void SetConnection(OracleConnection con) { localcon = con; }
- region Windows Form Designer generated code
/// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.localcon = new System.Data.OracleClient.OracleConnection(); this.oleDbInsertCommand1 = new System.Data.OracleClient.OracleCommand(); this.oleDbUpdateCommand1 = new System.Data.OracleClient.OracleCommand(); this.oleDbDeleteCommand1 = new System.Data.OracleClient.OracleCommand(); this.oleDbDataAdapter1 = new System.Data.OracleClient.OracleDataAdapter("select * from tasks", localcon); this.objTaskMaintenance = new Timesheet.TaskMaintenance(); this.btnLoad = new System.Windows.Forms.Button(); this.btnUpdate = new System.Windows.Forms.Button(); this.btnCancelAll = new System.Windows.Forms.Button(); this.grdTASK = new System.Windows.Forms.DataGrid(); this.oleDbCommand1 = new System.Data.OracleClient.OracleCommand(); ((System.ComponentModel.ISupportInitialize)(this.objTaskMaintenance)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.grdTASK)).BeginInit(); this.SuspendLayout();
// // oleDbConnection1 // this.localcon.ConnectionString = "User ID=darren;Password=darren;Data Source=;"; // // oleDbInsertCommand1 // // // oleDbDataAdapter1 // this.oleDbDataAdapter1.DeleteCommand = this.oleDbDeleteCommand1; this.oleDbDataAdapter1.InsertCommand = this.oleDbInsertCommand1; this.oleDbDataAdapter1.SelectCommand = this.oleDbCommand1; this.oleDbDataAdapter1.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] { new System.Data.Common.DataTableMapping("Table", "TASK", new System.Data.Common.DataColumnMapping[] { new System.Data.Common.DataColumnMapping("TASK_ABBREV", "TASK_ABBREV"), new System.Data.Common.DataColumnMapping("TASK_DESCR", "TASK_DESCR"), new System.Data.Common.DataColumnMapping("DEFAULT_PROJ_ABBREV", "DEFAULT_PROJ_ABBREV"), new System.Data.Common.DataColumnMapping("DEFAULT_APPL_ABBREV", "DEFAULT_APPL_ABBREV")})}); this.oleDbDataAdapter1.UpdateCommand = this.oleDbUpdateCommand1; // // objTaskMaintenance // this.objTaskMaintenance.DataSetName = "TaskMaintenance"; this.objTaskMaintenance.Locale = new System.Globalization.CultureInfo("en-GB"); // // Task_Maintenance? // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(424, 270); this.Controls.Add(this.btnLoad); this.Controls.Add(this.btnUpdate); this.Controls.Add(this.btnCancelAll); this.Controls.Add(this.grdTASK); this.Name = "Task_Maintenance"; this.Text = "Task_Maintenance"; ((System.ComponentModel.ISupportInitialize)(this.objTaskMaintenance)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.grdTASK)).EndInit(); this.ResumeLayout(false);
}
- endregion
public void FillDataSet(Timesheet.TaskMaintenance dataSet) { // Turn off constraint checking before the dataset is filled. // This allows the adapters to fill the dataset without concern // for dependencies between the tables. dataSet.EnforceConstraints = false; try { // Open the connection. this.localcon.Open(); // Attempt to fill the dataset through the OleDbDataAdapter1?. this.oleDbDataAdapter1.Fill(dataSet); } catch (System.Exception fillException) { // Add your error handling code here. throw fillException; } finally { // Turn constraint checking back on. dataSet.EnforceConstraints = true; // Close the connection whether or not the exception was thrown. this.localcon.Close(); }
}
public void UpdateDataSource(Timesheet.TaskMaintenance ChangedRows) { try { // The data source only needs to be updated if there are changes pending. if ChangedRows != null { // Open the connection. this.localcon.Open(); // Attempt to update the data source. oleDbDataAdapter1.Update(ChangedRows); } } catch (System.Exception updateException) { // Add your error handling code here. throw updateException; } finally { // Close the connection whether or not the exception was thrown. this.localcon.Close(); }
}
public void LoadDataSet() { // Create a new dataset to hold the records returned from the call to FillDataSet?. // A temporary dataset is used because filling the existing dataset would // require the databindings to be rebound. Timesheet.TaskMaintenance objDataSetTemp; objDataSetTemp = new Timesheet.TaskMaintenance(); try { // Attempt to fill the temporary dataset. this.FillDataSet(objDataSetTemp);
} catch (System.Exception eFillDataSet) { // Add your error handling code here. throw eFillDataSet; } try {
grdTASK.DataSource = localcon; // Empty the old records from the dataset. objTaskMaintenance.Clear(); // Merge the records into the main dataset. objTaskMaintenance.Merge(objDataSetTemp); grdTASK.SetDataBinding(objTaskMaintenance, "TASK"); } catch (System.Exception eLoadMerge) { // Add your error handling code here. throw eLoadMerge; }
}
public void UpdateDataSet() { // Create a new dataset to hold the changes that have been made to the main dataset. Timesheet.TaskMaintenance objDataSetChanges = new Timesheet.TaskMaintenance(); // Stop any current edits. this.BindingContextobjTaskMaintenance,"TASK".EndCurrentEdit(); // Get the changes that have been made to the main dataset. objDataSetChanges = ((Timesheet.TaskMaintenance)(objTaskMaintenance.GetChanges())); // Check to see if any changes have been made. if objDataSetChanges != null { try { // There are changes that need to be made, so attempt to update the datasource by // calling the update method and passing the dataset and any parameters. this.UpdateDataSource(objDataSetChanges); objTaskMaintenance.Merge(objDataSetChanges); objTaskMaintenance.AcceptChanges(); } catch (System.Exception eUpdate) { // Add your error handling code here. throw eUpdate; } // Add your code to check the returned dataset for any errors that may have been // pushed into the row object's error. }
}
private void btnCancelAll_Click(object sender, System.EventArgs e) { this.objTaskMaintenance.RejectChanges(); }
private void btnLoad_Click(object sender, System.EventArgs e) { try { this.LoadDataSet(); } catch (System.Exception eLoad) { // Add your error handling code here. // Display error message, if any. System.Windows.Forms.MessageBox.Show(eLoad.Message); }
}
private void btnUpdate_Click(object sender, System.EventArgs e) { try { // Attempt to update the datasource. this.UpdateDataSet(); } catch (System.Exception eUpdate) { // Add your error handling code here. // Display error message, if any. System.Windows.Forms.MessageBox.Show(eUpdate.Message); }
} } }
Apologies for the amount of code, i did not know how much to provide as im not sure whats relevant to my problem
I am getting the following error in a message box when i click the LOAD button: -
Fill: SelectCommand?.Connection property has not been initialized.
Could someone please advise me to what i have missed out as i am completely stumped?
Any help would be much appreciated!
|
|
|
|
|
Report
|
|
|
|
01-07-2006, 8:48 AM
|
azamsharp@gmail.com
Joined on 01-07-2006
Posts 1
|
Re: Filling a Dataset from an Oracle 10g Database
|
|
|
|
|
Hi,
It seems like you have not initialized the ConnectionString which means you are not correctly assigning the SqlConnection variable to the ConnectionString. Check in your code that you are correctly assigning SqlConnection.
Thanks, Azam
|
|
|
|
|
Report
|
|
|
|
| |
|