protected void DbDataAdapter_Fill_Ds(Sys.Data.Common.DbDataAdapter dbDA) { DataSet dsResult, dsExpected ; int ExpectedRowsCount,ResultRowsCount; DataSet ds = new DataSet(); ExpectedRowsCount = ReadDBData_Fill(dbDA,ref ds,false); // create expected dataset to compare result to dsExpected = ds.Copy(); //make some changes, the fill method will overides those changes with data from DB. foreach (DataRow dr in ds.Tables[0].Select()) dr["Country"] = "NeverNeverLand"; ds.Tables[0].Columns.Remove("HomePhone"); //remove column, this column will be addedd during the fill process //ds.Tables.Remove(ds.Tables[1]); //remove the table, this table will be addedd during the fill process ds.AcceptChanges(); // create source dataset to be filled dsResult = ds.Copy(); //execute fill ResultRowsCount = dbDA.Fill(dsResult); CompareResults_Fill(dsResult,dsExpected); //close connection if ( ((IDbDataAdapter)dbDA).SelectCommand.Connection.State != ConnectionState.Closed ) ((IDbDataAdapter)dbDA).SelectCommand.Connection.Close(); }
private static System.Data.DataTable GetDataSourceData(System.Data.Common.DbDataAdapter adapter, System.String namecolumn, System.String mailcolumn, System.String ownercolumn, System.String book) { if ( adapter==null ) return null; System.Data.DataTable data = GetDataSourceDataTable (namecolumn, mailcolumn, ownercolumn, book); try { adapter.Fill(data); } catch ( System.Exception e ) { if ( log.IsErrorEnabled ) log.Error("Error while doing query", e); return null; } return data; }
protected void DbDataAdapter_FillError(Sys.Data.Common.DbDataAdapter dbDA) { Exception exp = null; IDbDataAdapter Ida = (IDbDataAdapter)dbDA; IDbCommand ICmd = Ida.SelectCommand; IDbConnection IConn = ICmd.Connection; IConn.ConnectionString = MonoTests.System.Data.Utils.ConnectedDataProvider.ConnectionString; ICmd.CommandText = "SELECT CustomerID, CompanyName, City, Country, Phone FROM Customers "; IConn.Open(); DataSet ds = new DataSet(); ds.Tables.Add(new DataTable("Customers")); ds.Tables[0].Columns.Add("CustomerID",typeof(byte)); //check FillError event dbDA.FillError += new FillErrorEventHandler(dbDA_FillError); blnReadDBData_Fill = false; try { BeginCase("FillError"); try { dbDA.Fill(ds,"Customers"); } catch (Exception ){}; Compare(blnReadDBData_Fill ,true ); } catch(Exception ex) {exp = ex;} finally {EndCase(exp); exp = null;} dbDA.FillError -= new FillErrorEventHandler(dbDA_FillError); //close connection if ( ((IDbDataAdapter)dbDA).SelectCommand.Connection.State != ConnectionState.Closed ) ((IDbDataAdapter)dbDA).SelectCommand.Connection.Close(); }
protected void DbDataAdapter_Update_Ds_Str(Sys.Data.Common.DbDataAdapter dbDA) { int NumberOfAffectedRows = 0; Exception exp = null; // --------- get data from DB ----------------- DataSet ds = PrepareDBData_Update(dbDA); // --------- prepare dataset for update method ----------------- DataSet dsDB1 = ds.Copy(); // --------- prepare dataset for DBConcurrencyException ----------------- DataSet dsDB2 = ds.Copy(); //update dataset dsDB2.Tables[0].Rows.Add(new object[] {9994,"Ofer", "Borshtein", "Delete"}); dsDB2.Tables[0].Rows.Add(new object[] {9995,"Ofer", "Borshtein", "Update"}); dsDB2.Tables[0].Rows.Find(9996).Delete(); dsDB2.AcceptChanges(); dsDB1.Tables[0].Rows.Add(new object[] {9991,"Ofer","Borshtein","Insert"}); dsDB1.Tables[0].Rows.Find(9992).Delete(); dsDB1.Tables[0].Rows.Find(9993)["Title"] = "Jack the ripper"; //execute update to db NumberOfAffectedRows = dbDA.Update(dsDB1,dsDB1.Tables[0].TableName); try { BeginCase("Number Of Affected Rows"); Compare(NumberOfAffectedRows ,3 ); } catch(Exception ex) {exp = ex;} finally {EndCase(exp); exp = null;} //get result from db in order to check them DataSet dsExpected = new DataSet(); //ds.Reset(); dbDA.Fill(dsExpected); dsExpected.Tables[0].PrimaryKey = new DataColumn[] {dsExpected.Tables[0].Columns["EmployeeID"]}; CompareResults_Update(dsDB1,dsDB2,ref dbDA); CompareResults_Update_Ds_Str_Exception(dsDB2,ref dbDA); //Create rows which not exists in the DB but exists in the DS with row state = deleted //this will cause the Update to fail. dsDB1.Tables[0].Rows.Add(new object[] {9997,"Ofer", "Borshtein", "Delete"}); dsDB1.Tables[0].Rows.Add(new object[] {9998,"Ofer", "Borshtein", "Delete"}); dsDB1.AcceptChanges(); dsDB1.Tables[0].Rows.Find(9997).Delete(); dsDB1.Tables[0].Rows.Find(9998).Delete(); //Check Sys.Data.DBConcurrencyException //The exception that is thrown by the DataAdapter during the update operation if the number of rows affected equals zero. try { BeginCase("Check DBConcurrencyException"); try { NumberOfAffectedRows = dbDA.Update(dsDB1,dsDB1.Tables[0].TableName); } catch (DBConcurrencyException ex) {exp=ex;} Compare(exp.GetType(),typeof(DBConcurrencyException) ); exp = null; } catch(Exception ex) {exp = ex;} finally {EndCase(exp); exp = null;} //close connection if ( ((IDbDataAdapter)dbDA).SelectCommand.Connection.State != ConnectionState.Closed ) ((IDbDataAdapter)dbDA).SelectCommand.Connection.Close(); }
protected void DataAdapter_MissingSchemaAction(Sys.Data.Common.DbDataAdapter dbDA) { Exception exp = null; IDbDataAdapter Ida = (IDbDataAdapter)dbDA; IDbCommand ICmd = Ida.SelectCommand; IDbConnection IConn = ICmd.Connection; IConn.ConnectionString = MonoTests.System.Data.Utils.ConnectedDataProvider.ConnectionString; // IConn.Open(); PrepareDataForTesting( MonoTests.System.Data.Utils.ConnectedDataProvider.ConnectionString); IConn.Open(); //get the total rows count ICmd.CommandText = "SELECT Count(*) FROM Customers where CustomerID in ('GH100','GH200','GH300','GH400','GH500','GH600','GH700')"; int ExpectedRows = Sys.Convert.ToInt32(ICmd.ExecuteScalar()); try { BeginCase("Check that Expected rows count > 0"); Compare(ExpectedRows > 0 ,true); } catch(Exception ex) {exp = ex;} finally {EndCase(exp); exp = null;} ICmd.CommandText = "SELECT CustomerID, CompanyName, City, Country, Phone FROM Customers where CustomerID in ('GH100','GH200','GH300','GH400','GH500','GH600','GH700')"; //get db type DBType = ConnectedDataProvider.GetDbType(((IDbDataAdapter)dbDA).SelectCommand.Connection.ConnectionString); //init dataset DataSet ds = new DataSet(); try { BeginCase("Execute Fill - check return rows count"); int i = dbDA.Fill(ds); Compare(i ,ExpectedRows ); } catch(Exception ex) {exp = ex;} finally {EndCase(exp); exp = null;} //make dataset schema mismatch with DB ds.Tables[0].Columns.Remove("Country"); ds.Tables[0].Clear(); //--- Default value --- try { BeginCase("MissingSchemaAction Default value"); Compare(dbDA.MissingSchemaAction, MissingSchemaAction.Add); } catch(Exception ex) {exp = ex;} finally {EndCase(exp); exp = null;} //--- MissingSchemaAction.Error --- ds.Tables[0].Clear(); dbDA.MissingSchemaAction = MissingSchemaAction.Error ; Exception ExMissingSchemaAction = null; try { BeginCase("MissingSchemaAction.Error"); try { dbDA.Fill(ds); } catch (InvalidOperationException e) { ExMissingSchemaAction = e; } Compare(ExMissingSchemaAction.GetType() ,typeof(InvalidOperationException)); } catch(Exception ex) {exp = ex;} finally {EndCase(exp); exp = null;} try { BeginCase("MissingSchemaAction.Error, Row.Count = 0"); Compare(ds.Tables[0].Rows.Count , 0 ); } catch(Exception ex) {exp = ex;} finally {EndCase(exp); exp = null;} try { BeginCase("MissingSchemaAction.Error, Column"); Compare(ds.Tables[0].Columns.IndexOf("Country") , -1 ); } catch(Exception ex) {exp = ex;} finally {EndCase(exp); exp = null;} //--- MissingSchemaAction.Ignore --- try { //catch any exception that might occure BeginCase("MissingSchemaAction.Ignore - invoke"); ds.Tables[0].Clear(); dbDA.MissingSchemaAction = MissingSchemaAction.Ignore ; ExMissingSchemaAction = null; dbDA.Fill(ds); Compare(true ,true); } catch(Exception ex) {exp = ex;} finally {EndCase(exp); exp = null;} try { BeginCase("MissingSchemaAction.Ignore, Row.Count = 0"); Compare(ds.Tables[0].Rows.Count > 0 ,true); } catch(Exception ex) {exp = ex;} finally {EndCase(exp); exp = null;} try { BeginCase("MissingSchemaAction.Ignore, Column"); Compare(ds.Tables[0].Columns.IndexOf("Country") , -1 ); } catch(Exception ex) {exp = ex;} finally {EndCase(exp); exp = null;} #if !KNOWN_BUG //BUG_NUM:1951 try { BeginCase("MissingSchemaAction.Ignore, PrimaryKey"); Compare(ds.Tables[0].PrimaryKey.Length == 0 ,true ); } catch(Exception ex) {exp = ex;} finally {EndCase(exp); exp = null;} #endif //--- MissingSchemaAction.Add --- try { //catch any exception that might occure BeginCase("MissingSchemaAction.Add - invoke"); ds.Tables[0].Clear(); dbDA.MissingSchemaAction = MissingSchemaAction.Add ; ExMissingSchemaAction = null; dbDA.Fill(ds); Compare(true ,true); } catch(Exception ex) {exp = ex;} finally {EndCase(exp); exp = null;} try { BeginCase("MissingSchemaAction.Add, Row.Count > 0"); Compare(ds.Tables[0].Rows.Count >= 0 ,true ); } catch(Exception ex) {exp = ex;} finally {EndCase(exp); exp = null;} try { BeginCase("MissingSchemaAction.Add, Column"); Compare(ds.Tables[0].Columns.IndexOf("Country") >= 0 ,true ); } catch(Exception ex) {exp = ex;} finally {EndCase(exp); exp = null;} #if !KNOWN_BUG //BUG_NUM:1952 //DB2 don't return primary key if (DBType != DataBaseServer.DB2) { try { BeginCase("MissingSchemaAction.AddWithKey, PrimaryKey"); Compare(ds.Tables[0].PrimaryKey.Length ,0); } catch(Exception ex) {exp = ex;} finally {EndCase(exp); exp = null;} } //--- MissingSchemaAction.AddWithKey --- try { //catch any exception that might occure BeginCase("MissingSchemaAction.AddWithKey - invoke"); ds.Tables[0].Clear(); ds.Tables[0].Columns.Remove("Country"); dbDA.MissingSchemaAction = MissingSchemaAction.AddWithKey ; ExMissingSchemaAction = null; dbDA.Fill(ds); Compare(true ,true); } catch(Exception ex) {exp = ex;} finally {EndCase(exp); exp = null;} try { BeginCase("MissingSchemaAction.AddWithKey, Row.Count > 0"); Compare(ds.Tables[0].Rows.Count >= 0 ,true ); } catch(Exception ex) {exp = ex;} finally {EndCase(exp); exp = null;} try { BeginCase("MissingSchemaAction.AddWithKey, Column"); Compare(ds.Tables[0].Columns.IndexOf("Country") >= 0 ,true ); } catch(Exception ex) {exp = ex;} finally {EndCase(exp); exp = null;} //DB2 don't return primary key if (DBType != DataBaseServer.DB2 && DBType != DataBaseServer.Oracle) { try { BeginCase("MissingSchemaAction.AddWithKey, PrimaryKey"); Compare(ds.Tables[0].PrimaryKey.Length > 0 ,true ); } catch(Exception ex) {exp = ex;} finally {EndCase(exp); exp = null;} } #endif //close connection if ( ((IDbDataAdapter)dbDA).SelectCommand.Connection.State != ConnectionState.Closed ) ((IDbDataAdapter)dbDA).SelectCommand.Connection.Close(); }
protected void DataAdapter_MissingMappingAction(Sys.Data.Common.DbDataAdapter dbDA) { Exception exp = null; IDbDataAdapter Ida = (IDbDataAdapter)dbDA; IDbCommand ICmd = Ida.SelectCommand; IDbConnection IConn = ICmd.Connection; IConn.ConnectionString = MonoTests.System.Data.Utils.ConnectedDataProvider.ConnectionString; // IConn.Open(); //get the total rows count PrepareDataForTesting( MonoTests.System.Data.Utils.ConnectedDataProvider.ConnectionString); IConn.Open(); ICmd.CommandText = "SELECT Count(*) FROM Customers where CustomerID in ('GH100','GH200','GH300','GH400','GH500','GH600','GH700')"; int ExpectedRows = Sys.Convert.ToInt32(ICmd.ExecuteScalar()); try { BeginCase("Check that Expected rows count > 0"); Compare(ExpectedRows > 0 ,true); } catch(Exception ex) {exp = ex;} finally {EndCase(exp); exp = null;} ICmd.CommandText = "SELECT CustomerID, CompanyName, City, Country, Phone FROM Customers where CustomerID in ('GH100','GH200','GH300','GH400','GH500','GH600','GH700')"; //init dataset DataSet ds = new DataSet(); try { BeginCase("Execute Fill - check return rows count"); int i = dbDA.Fill(ds); Compare(i ,ExpectedRows ); } catch(Exception ex) {exp = ex;} finally {EndCase(exp); exp = null;} //make dataset schema mismatch with DB ds.Tables[0].Columns.Remove("Country"); ds.Tables[0].Clear(); //--- Default value --- try { BeginCase("MissingMappingAction Default value"); Compare(dbDA.MissingMappingAction , MissingMappingAction.Passthrough); } catch(Exception ex) {exp = ex;} finally {EndCase(exp); exp = null;} //--- MissingMappingAction.Error --- ds.Tables[0].Clear(); dbDA.MissingMappingAction = MissingMappingAction.Error ; Exception ExMissingMappingAction = null; try { BeginCase("MissingMappingAction.Error"); try { dbDA.Fill(ds); } catch (InvalidOperationException e) { ExMissingMappingAction = e; } Compare(ExMissingMappingAction.GetType() ,typeof(InvalidOperationException)); } catch(Exception ex) {exp = ex;} finally {EndCase(exp); exp = null;} try { BeginCase("MissingMappingAction.Error, Row.Count = 0"); Compare(ds.Tables[0].Rows.Count , 0 ); } catch(Exception ex) {exp = ex;} finally {EndCase(exp); exp = null;} try { BeginCase("MissingMappingAction.Error, Column"); Compare(ds.Tables[0].Columns.IndexOf("Country") , -1 ); } catch(Exception ex) {exp = ex;} finally {EndCase(exp); exp = null;} //--- MissingMappingAction.Ignore --- ds.Tables[0].Clear(); dbDA.MissingMappingAction = MissingMappingAction.Ignore ; ExMissingMappingAction = null; try { BeginCase("MissingMappingAction.Ignore"); try { dbDA.Fill(ds); } catch (InvalidOperationException e) { ExMissingMappingAction = e; } Compare(ExMissingMappingAction ,null); } catch(Exception ex) {exp = ex;} finally {EndCase(exp); exp = null;} try { BeginCase("MissingMappingAction.Ignore, Row.Count = 0"); Compare(ds.Tables[0].Rows.Count ,0); } catch(Exception ex) {exp = ex;} finally {EndCase(exp); exp = null;} try { BeginCase("MissingMappingAction.Ignore, Column"); Compare(ds.Tables[0].Columns.IndexOf("Country") , -1 ); } catch(Exception ex) {exp = ex;} finally {EndCase(exp); exp = null;} //--- MissingMappingAction.Passthrough --- ds.Tables[0].Clear(); dbDA.MissingMappingAction = MissingMappingAction.Passthrough ; ExMissingMappingAction = null; try { BeginCase("MissingMappingAction.Passthrough"); try { dbDA.Fill(ds); } catch (InvalidOperationException e) { ExMissingMappingAction = e; } Compare(ExMissingMappingAction ,null); } catch(Exception ex) {exp = ex;} finally {EndCase(exp); exp = null;} try { BeginCase("MissingMappingAction.Passthrough, Row.Count > 0"); Compare(ds.Tables[0].Rows.Count >= 0 ,true ); } catch(Exception ex) {exp = ex;} finally {EndCase(exp); exp = null;} try { BeginCase("MissingMappingAction.Passthrough, Column"); Compare(ds.Tables[0].Columns.IndexOf("Country") >= 0 ,true ); } catch(Exception ex) {exp = ex;} finally {EndCase(exp); exp = null;} //close connection if ( ((IDbDataAdapter)dbDA).SelectCommand.Connection.State != ConnectionState.Closed ) ((IDbDataAdapter)dbDA).SelectCommand.Connection.Close(); }
protected void DataAdapter_ContinueUpdateOnError(Sys.Data.Common.DbDataAdapter dbDA) { /* !!!!!! Not working (TestName "ContinueUpdateOnError - true, check value 2")!!!!! If ContinueUpdateOnError is set to true, no exception is thrown when an error occurs during the update of a row. The update of the row is skipped and the error information is placed in the RowError property of the row in error. The DataAdapter continues to update subsequent rows. If ContinueUpdateOnError is set to false, an exception is thrown when an error occurs during the update of a row. */ Exception exp = null; IDbDataAdapter Ida = (IDbDataAdapter)dbDA; IDbCommand ICmd = Ida.SelectCommand; IDbConnection IConn = ICmd.Connection; IConn.ConnectionString = MonoTests.System.Data.Utils.ConnectedDataProvider.ConnectionString; PrepareDataForTesting( MonoTests.System.Data.Utils.ConnectedDataProvider.ConnectionString); IConn.Open(); //get the total rows count ICmd.CommandText = "SELECT Count(*) FROM Customers where CustomerID in ('GH100','GH200','GH300','GH400','GH500','GH600','GH700')"; int ExpectedRows = Sys.Convert.ToInt32(ICmd.ExecuteScalar()); try { BeginCase("Check that Expected rows count > 0"); Compare(ExpectedRows > 0 ,true); } catch(Exception ex) {exp = ex;} finally {EndCase(exp); exp = null;} ICmd.CommandText = "SELECT CustomerID, CompanyName, City, Country, Phone FROM Customers where CustomerID in ('GH100','GH200','GH300','GH400','GH500','GH600','GH700')"; DataSet dsMem = new DataSet(); //Disconected dataset DataSet dsDB = new DataSet(); //DataBase data dbDA.AcceptChangesDuringFill = true; //get data from DB try { BeginCase("Execute Fill - check return rows count"); int i = dbDA.Fill(dsMem); Compare(i ,ExpectedRows ); } catch(Exception ex) {exp = ex;} finally {EndCase(exp); exp = null;} //update data with invalid information (Max. length for Phone is 24) // 123456789012345678901234 string newValue1 = "Very Long String That Will Raise An Error Yep!"; string oldValue1 = dsMem.Tables[0].Rows[3]["Phone"].ToString(); string oldValue2 = dsMem.Tables[0].Rows[4]["Phone"].ToString(); string newValue2 = "03-1234"; dsMem.Tables[0].Rows[3]["Phone"] = newValue1; dsMem.Tables[0].Rows[4]["Phone"] = newValue2; dbDA.ContinueUpdateOnError = true; //will not throw exception try { BeginCase("ContinueUpdateOnError - true, check exception"); try { dbDA.Update(dsMem); } catch(Exception ex){exp = ex;} Compare(exp == null,true); exp = null; } catch(Exception ex) {exp = ex;} finally {EndCase(exp); exp = null;} dbDA.Fill(dsDB); //get data from DB to check the update operation try { BeginCase("ContinueUpdateOnError - true, check RowError"); Compare(dsMem.Tables[0].Rows[3].RowError.Length > 0 , true); } catch(Exception ex) {exp = ex;} finally {EndCase(exp); exp = null;} try { BeginCase("ContinueUpdateOnError - true, check value 1"); Compare(dsDB.Tables[0].Rows[3]["Phone"] , oldValue1); } catch(Exception ex) {exp = ex;} finally {EndCase(exp); exp = null;} /* - Test excluded, it is not working in .NET too! //should continue the update try { BeginCase("ContinueUpdateOnError - true, check value 2"); Compare(dsDB.Tables[0].Rows[4]["Phone"] , newValue2); //--------- NOT WORKING !!! ----------- } catch(Exception ex) {exp = ex;} finally {EndCase(exp); exp = null;} */ dsMem.Reset(); dsDB.Reset(); dbDA.Fill(dsMem); dsMem.Tables[0].Rows[3]["Phone"] = newValue1 ; dsMem.Tables[0].Rows[4]["Phone"] = newValue2; dbDA.ContinueUpdateOnError = false; try { BeginCase("ContinueUpdateOnError - false, check exception"); try { dbDA.Update(dsMem); } catch(Exception ex){exp = ex;} Compare(exp == null,false); exp = null; } catch(Exception ex) {exp = ex;} finally {EndCase(exp); exp = null;} dbDA.Fill(dsDB); //get data from DB to check the update operation try { BeginCase("ContinueUpdateOnError - false,check RowError"); Compare(dsMem.Tables[0].Rows[3].RowError.Length > 0 ,true); } catch(Exception ex) {exp = ex;} finally {EndCase(exp); exp = null;} try { BeginCase("ContinueUpdateOnError - false,check value 1"); Compare(dsDB.Tables[0].Rows[3]["Phone"] , oldValue1 ); } catch(Exception ex) {exp = ex;} finally {EndCase(exp); exp = null;} try { BeginCase("ContinueUpdateOnError - false,check value 2"); Compare(dsDB.Tables[0].Rows[4]["Phone"] , oldValue2 ); } catch(Exception ex) {exp = ex;} finally {EndCase(exp); exp = null;} //close connection if ( ((IDbDataAdapter)dbDA).SelectCommand.Connection.State != ConnectionState.Closed ) ((IDbDataAdapter)dbDA).SelectCommand.Connection.Close(); }
protected void DataAdapter_AcceptChangesDuringFill(Sys.Data.Common.DbDataAdapter dbDA) { Exception exp = null; IDbDataAdapter Ida = (IDbDataAdapter)dbDA; IDbCommand ICmd = Ida.SelectCommand; IDbConnection IConn = ICmd.Connection; IConn.ConnectionString = MonoTests.System.Data.Utils.ConnectedDataProvider.ConnectionString; PrepareDataForTesting( MonoTests.System.Data.Utils.ConnectedDataProvider.ConnectionString); IConn.Open(); //get the total rows count ICmd.CommandText = "SELECT Count(*) FROM Customers where CustomerID in ('GH100','GH200','GH300','GH400','GH500','GH600','GH700')"; int ExpectedRows = Sys.Convert.ToInt32(ICmd.ExecuteScalar()); try { BeginCase("Check that Expected rows count > 0"); Compare(ExpectedRows > 0 ,true); } catch(Exception ex) {exp = ex;} finally {EndCase(exp); exp = null;} ICmd.CommandText = "SELECT CustomerID, CompanyName, City, Country, Phone FROM Customers where CustomerID in ('GH100','GH200','GH300','GH400','GH500','GH600','GH700')"; DataSet ds = new DataSet(); dbDA.AcceptChangesDuringFill = false; try { BeginCase("Execute Fill - check return rows count"); int i = dbDA.Fill(ds); Compare(i ,ExpectedRows ); } catch(Exception ex) {exp = ex;} finally {EndCase(exp); exp = null;} bool blnAcceptChanges = false; foreach (DataRow dr in ds.Tables[0].Rows) { if (dr.RowState != DataRowState.Added ) { blnAcceptChanges = true; break; } } try { BeginCase("AcceptChangesDuringFill - false"); Compare(blnAcceptChanges ,false ); } catch(Exception ex) {exp = ex;} finally {EndCase(exp); exp = null;} ds.Reset(); dbDA.AcceptChangesDuringFill = true; dbDA.Fill(ds); blnAcceptChanges = false; foreach (DataRow dr in ds.Tables[0].Rows) { if (dr.RowState != DataRowState.Unchanged ) { blnAcceptChanges = true; break; } } try { BeginCase("AcceptChangesDuringFill - true"); Compare(blnAcceptChanges ,false ); } catch(Exception ex) {exp = ex;} finally {EndCase(exp); exp = null;} //close connection if ( ((IDbDataAdapter)dbDA).SelectCommand.Connection.State != ConnectionState.Closed ) ((IDbDataAdapter)dbDA).SelectCommand.Connection.Close(); }
protected DataSet PrepareDBData_Update(Sys.Data.Common.DbDataAdapter dbDA,bool sqlConnectionString) { IDbDataAdapter Ida = (IDbDataAdapter)dbDA; IDbCommand ICmd = Ida.SelectCommand; ICmd.CommandText = "SELECT EmployeeID, LastName, FirstName, Title FROM Employees WHERE EmployeeID in (9991,9992,9993,9994,9995,9996)"; IDbConnection IConn = ICmd.Connection; if (!sqlConnectionString) { IConn.ConnectionString = MonoTests.System.Data.Utils.ConnectedDataProvider.ConnectionString; } IConn.Open(); //Insert rows to be updated (insert,delete,update) IDbCommand cmd; if (sqlConnectionString) { cmd = new Sys.Data.SqlClient.SqlCommand(); cmd.Connection = (Sys.Data.SqlClient.SqlConnection)IConn; } else { cmd = new Sys.Data.OracleClient.OracleCommand(); cmd.Connection = (Sys.Data.OracleClient.OracleConnection)IConn; } //run execute after each command because DB2 doesn't support multiple commands cmd.CommandText = "DELETE FROM Employees WHERE EmployeeID in (9991,9992,9993,9994,9995,9996,9997,9998)"; cmd.ExecuteNonQuery(); //only for SQL Server DataBaseServer DBType = ConnectedDataProvider.GetDbType(IConn.ConnectionString); cmd.CommandText = "INSERT INTO Employees (EmployeeID, LastName, FirstName, Title) VALUES(9992, 'Ofer', 'Borshtein', 'delete')"; //if (DBType == DataBaseServer.SQLServer) cmd.CommandText = "SET IDENTITY_INSERT Employees ON;" + cmd.CommandText; cmd.ExecuteNonQuery(); cmd.CommandText = "INSERT INTO Employees (EmployeeID, LastName, FirstName, Title) VALUES(9993, 'Ofer', 'Borshtein', 'Update')"; //if (DBType == DataBaseServer.SQLServer) cmd.CommandText = "SET IDENTITY_INSERT Employees ON;" + cmd.CommandText; cmd.ExecuteNonQuery(); cmd.CommandText = "INSERT INTO Employees (EmployeeID, LastName, FirstName, Title) VALUES(9996, 'Ofer', 'Borshtein', 'Exp')"; //if (DBType == DataBaseServer.SQLServer) cmd.CommandText = "SET IDENTITY_INSERT Employees ON;" + cmd.CommandText; cmd.ExecuteNonQuery(); //cmd.CommandText += "INSERT INTO Employees (EmployeeID, LastName, FirstName, Title) VALUES(9991, 'Ofer', 'Borshtein', 'Insert'); "; //cmd.CommandText += "INSERT INTO Employees (EmployeeID, LastName, FirstName, Title) VALUES(9994, 'Ofer', 'Borshtein', 'Exp'); "; //cmd.CommandText += "INSERT INTO Employees (EmployeeID, LastName, FirstName, Title) VALUES(9995, 'Ofer', 'Borshtein', 'Exp'); "; //cmd.CommandText += "INSERT INTO Employees (EmployeeID, LastName, FirstName, Title) VALUES(9997, 'Ofer', 'Borshtein', 'delete'); "; //cmd.CommandText += "INSERT INTO Employees (EmployeeID, LastName, FirstName, Title) VALUES(9998, 'Ofer', 'Borshtein', 'delete'); "; DataSet ds = new DataSet(); dbDA.Fill(ds); ds.Tables[0].PrimaryKey = new DataColumn[] {ds.Tables[0].Columns["EmployeeID"]}; return ds; }