Shalex, i am sorry for the incovinience. Let me say that i have tried to get this working for a very long time, with no success.
Let me answer your question
1) The version is 5.20.33.0 Professional Edition
2) I generated the typed dataset for the 2 tables emp and dept using the wizard (next to the end of the wizard). With out touching a single line of code, the InitClass method looks like the folowing
Code: Select all
[System.Diagnostics.DebuggerNonUserCodeAttribute()]
private void InitClass() {
this.DataSetName = "DataSet";
this.Prefix = "";
this.EnforceConstraints = true;
this.SchemaSerializationMode = System.Data.SchemaSerializationMode.IncludeSchema;
this.Connection = new Devart.Data.Oracle.OracleConnection("User Id=sistema;Password=mistralsi;Server=SZICOM.LIT.DESA;Home=OraClient10g_home4" +
";Persist Security Info=True;");
this.tableDEPT = new DEPTDataTable(this.Connection);
base.Tables.Add(this.tableDEPT);
this.tableEMP = new EMPDataTable(this.Connection);
base.Tables.Add(this.tableEMP);
System.Data.ForeignKeyConstraint fkc;
fkc = new System.Data.ForeignKeyConstraint("FK_DEPTNO", new System.Data.DataColumn[] {
this.tableDEPT.DEPTNOColumn}, new System.Data.DataColumn[] {
this.tableEMP.DEPTNOColumn});
this.tableEMP.Constraints.Add(fkc);
fkc.AcceptRejectRule = System.Data.AcceptRejectRule.None;
fkc.DeleteRule = System.Data.Rule.None;
fkc.UpdateRule = System.Data.Rule.None;
this.relationFK_DEPTNO = new System.Data.DataRelation("FK_DEPTNO", new System.Data.DataColumn[] {
this.tableDEPT.DEPTNOColumn}, new System.Data.DataColumn[] {
this.tableEMP.DEPTNOColumn}, false);
this.Relations.Add(this.relationFK_DEPTNO);
}
The problem comes when i want to use a different connection than the one that is is beaing created in the InitClass method. I have concluded (i may be wrong) that the DataSet's connection is pass to the DataTable in their constructor. Then each datatable constructor's passes this connections to each command (SelectCommand, InsertCommand, UpdateCommand and DeleteCommand ), as seen in the code generated in the following method:
Code: Select all
public EMPDataTable(Devart.Data.Oracle.OracleConnection connection) {
this.TableName = "EMP";
this.Name = "EMP";
this.Connection = connection; <--This connection is referencing the one created for the dataset.
this.BeginInit();
this.InitClass();
this.EndInit();
}
This causes that the OracleDataTable (Emp and Dept) passes to each of the four OracleCommand (Select, Insert, Update,Delete) the connection of the dataset.
So when at runtime you create a dataset and set the DataSet's Connection property to a new OracleConnection. The DataTables inside the DataSet still reference the old OracleConnection (created in the InitClass method). Then (according to your example) i have to set the SelectCommand.Connectio to the new OracleConnection. But the problem is that when you call the Update method, the underlaying commands (Insert, Update, Delete) still reference the old connection and not the new one.
As an example i will post the code you wrote and the one i have to write to achieve what i want
Code: Select all
OracleConnection conn = new OracleConnection();
//dataset was created with a different connection string
conn.ConnectionString = "server=orcl1020;uid=scott;pwd=tiger;";
DataSet1 dsTest = new DataSet1();
dsTest.Connection = conn;
dsTest.DEPT.Connection = conn;
dsTest.Connection.Open();
OracleDataAdapter adapter = new OracleDataAdapter();
adapter.SelectCommand = dsTest.DEPT.SelectCommand;
adapter.Fill(dsTest.DEPT);
DataRow row = dsTest.DEPT.NewRow();
row[0] = 50;
row[1] = "asdf";
row[2] = "asdf";
dsTest.DEPT.AddDEPTRow((DataSet1.DEPTRow)row);
dsTest.Update();
and this is my code
Code: Select all
OracleConnection conn = new OracleConnection();
//dataset was created with a different connection string
conn.ConnectionString = "server=orcl1020;uid=scott;pwd=tiger;";
DataSet1 dsTest = new DataSet1();
dsTest.Connection = conn;
dsTest.DEPT.Connection = conn;
dsTest.DEPT.InsertCommand.Connection = conn; <--Otherwise it point's to the old connection.
dsTest.DEPT.UpdateCommand.Connection = conn; <-- If you debug, you will see that the underlaying connection
dsTest.DEPT.DeleteCommand.Connection = conn; <-- is the one define in the InitClass
dsTest.Connection.Open();
OracleDataAdapter adapter = new OracleDataAdapter();
adapter.SelectCommand = dsTest.DEPT.SelectCommand;
adapter.Fill(dsTest.DEPT);
DataRow row = dsTest.DEPT.NewRow();
row[0] = 50;
row[1] = "asdf";
row[2] = "asdf";
dsTest.DEPT.AddDEPTRow((DataSet1.DEPTRow)row);
dsTest.Update();
[/quote]