本文整理汇总了C#中System.Data.DataSet.Copy方法的典型用法代码示例。如果您正苦于以下问题:C# DataSet.Copy方法的具体用法?C# DataSet.Copy怎么用?C# DataSet.Copy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Data.DataSet
的用法示例。
在下文中一共展示了DataSet.Copy方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: run
public void run()
{
Exception exp = null;
DataSet ds1 = new DataSet();
ds1.Tables.Add(GHTUtils.DataProvider.CreateParentDataTable());
ds1.Tables.Add(GHTUtils.DataProvider.CreateChildDataTable());
//add data to check GH bug of DataSet.ReadXml of empty strings
ds1.Tables[1].Rows.Add(new object[] {7,1,string.Empty,string.Empty,new DateTime(2000,1,1,0,0,0,0),35});
ds1.Tables[1].Rows.Add(new object[] {7,2," "," ",new DateTime(2000,1,1,0,0,0,0),35});
ds1.Tables[1].Rows.Add(new object[] {7,3,"","",new DateTime(2000,1,1,0,0,0,0),35});
System.IO.StringWriter sw = new System.IO.StringWriter();
//write xml file, data only
ds1.WriteXml(sw);
//copy both data and schema
DataSet ds2 = ds1.Copy();
//clear the data
ds2.Clear();
System.IO.StringReader sr = new System.IO.StringReader(sw.GetStringBuilder().ToString());
ds2.ReadXml(sr);
//check xml data
try
{
BeginCase("ReadXml - Tables count");
Compare(ds1.Tables.Count ,ds2.Tables.Count );
}
catch(Exception ex) {exp = ex;}
finally {EndCase(exp); exp = null;}
try
{
BeginCase("ReadXml - Table 1 row count");
Compare(ds1.Tables[0].Rows.Count ,ds2.Tables[0].Rows.Count);
}
catch(Exception ex) {exp = ex;}
finally {EndCase(exp); exp = null;}
try
{
BeginCase("ReadXml - Table 2 row count");
Compare(ds1.Tables[1].Rows.Count ,ds2.Tables[1].Rows.Count);
}
catch(Exception ex) {exp = ex;}
finally {EndCase(exp); exp = null;}
sr.Close();
sw.Close();
}
示例2: SaveSounds
public static void SaveSounds(DataSet ds)
{
DataSet newDs = ds.Copy();
foreach (DataTable dt in newDs.Tables)
{
dt.Columns.Remove("buffer");
}
StreamWriter xmlWriter = new StreamWriter("settings\\sound_data.xml");
newDs.WriteXml(xmlWriter);
xmlWriter.Close();
}
示例3: PostToFile
public PostToFile(string mstTable, string key, string selectFields, string where, string delFlag, DataSet dsSite, string action, bool logFlg,string userName)
{
this.mstTable = mstTable;
this.selectFields = selectFields;
this.where = where;
this.delFlag = delFlag;
this.dsSite = dsSite.Copy();
this.action = action;
this.logFlg = logFlg;
this.key = key;
this.userName = userName;
}
示例4: Execute
public void Execute(byte[] reportData, DataSet ds)
{
if (this.caller != null)
{
string str = ds.Tables["YW_ZQRSF"].Rows[0]["PROJECT_ID"].ToString();
string localpath = FileUtility.Combine(new string[] { FileUtility.ApplicationRootPath, "CameraProject", str });
DataSet set = ds.Copy();
set.Tables.Add(this.AddImgTable(localpath, this.caller.CIS[0].Identifies, "ZRFPics"));
set.Tables.Add(this.AddImgTable(localpath, this.caller.CIS[1].Identifies, "SRFPics"));
PrintHelper.PrintOrShowRDLC("二手房转让确认书", true, reportData, set, null, null, null);
}
}
示例5: DataSetMerageTest
/// <summary>
/// 测试不同schema的DataSet 合并规则
/// 合并会将Schema同步过去
/// </summary>
public static void DataSetMerageTest()
{
var dsSource = new DataSet();
var dtSrc = new DataTable("SrcDT");
dtSrc.Columns.Add("Id", typeof(string));
dtSrc.Columns.Add("COde", typeof(string));
dsSource.Tables.Add(dtSrc);
var dest = dsSource.Copy();
dtSrc.Columns.Add("Desc", typeof(string));
var dr = dtSrc.NewRow();
dr["Id"] = "1";
dr["Code"] = "No001";
dr["Desc"] = "First";
dtSrc.Rows.Add(dr);
dest.Merge(dsSource);
}
示例6: Update
public void Update(DataSet ds, IDbCommandBuilder dbCommandBuilder, IDbTransaction dbTransaction)
{
DataSet dsCopy = ds.Copy();
dsCopy.AcceptChanges();
DataSetTableIterator iterator = new DataSetTableIterator(dsCopy, true);
foreach (DataTable dataTable in iterator)
{
foreach (DataRow dataRow in dataTable.Rows)
{
// Modify every table row.
dataRow.BeginEdit();
dataRow.EndEdit();
}
OnUpdate(dsCopy, dbCommandBuilder, dbTransaction, dataTable.TableName);
}
}
示例7: run
//Activate This Construntor to log All To Standard output
//public TestClass():base(true){}
//Activate this constructor to log Failures to a log file
//public TestClass(System.IO.TextWriter tw):base(tw, false){}
//Activate this constructor to log All to a log file
//public TestClass(System.IO.TextWriter tw):base(tw, true){}
//BY DEFAULT LOGGING IS DONE TO THE STANDARD OUTPUT ONLY FOR FAILURES
public void run()
{
Exception exp = null;
DataSet ds1,ds2 = new DataSet();
ds2.Tables.Add(GHTUtils.DataProvider.CreateParentDataTable());
ds1 = ds2.Copy();
//create changes
ds2.Tables[0].Rows[0][0] = "70";
ds2.Tables[0].Rows[1].Delete();
ds2.Tables[0].Rows.Add(new object[] {9,"string1","string2"});
try
{
BeginCase("RejectChanges");
ds2.RejectChanges();
Compare(ds1.GetXml(),ds2.GetXml());
}
catch(Exception ex) {exp = ex;}
finally {EndCase(exp); exp = null;}
}
示例8: VerifySqlProjFile
internal static bool VerifySqlProjFile(DataSet ds, string sqlProjPath)
{
DataTable dt = null;
bool hasChanges = false;
string ver = "2.6.0.0";
string asmName = "yukondeploy,version=2.6.0.0,culture=neutral,publickeytoken=837e5cc1726a2c56";
dt = ds.Tables["UsingTask"];
foreach (DataRow row in dt.Rows)
{
if (!row["AssemblyName"].ToString().Contains(ver))
{
row["AssemblyName"] = asmName;
hasChanges = true;
}
}
//create the table which will hold the projfile with
DataTable dtFile = new DataTable();
dtFile.Columns.Add(new DataColumn("TableName", typeof(string)));
dtFile.Columns.Add(new DataColumn("ColumnName", typeof(string)));
dtFile.Columns.Add(new DataColumn("TypeName", typeof(string)));
dtFile.Columns.Add(new DataColumn("ObjectValue", typeof(object)));
dtFile.Columns.Add(new DataColumn("MapType", typeof(MappingType)));
//add values
dtFile.Rows.Add(new object[] { "PropertyGroup", "Assemblyname", "System.String", "$(AssemblyName)", MappingType.Element });
dtFile.Rows.Add(new object[] { "PropertyGroup", "Alterassembly", "System.Boolean", false, MappingType.Element });
dtFile.Rows.Add(new object[] { "PropertyGroup", "Uncheckeddata", "System.Boolean", false, MappingType.Element });
dtFile.Rows.Add(new object[] { "PropertyGroup", "Permissionset", "System.Int32", 0, MappingType.Element });
dtFile.Rows.Add(new object[] { "PropertyGroup", "ConnectDatabase", "System.Boolean", true, MappingType.Element });
dtFile.Rows.Add(new object[] { "PropertyGroup", "Connectionstring", "System.String", "server=localhost;database=[DB_NAME];Integrated Security='SSPI'", MappingType.Element });
dtFile.Rows.Add(new object[] { "PropertyGroup", "Infermethods", "System.Boolean", false, MappingType.Element });
dtFile.Rows.Add(new object[] { "PropertyGroup", "DropTable", "System.Boolean", true, MappingType.Element });
dtFile.Rows.Add(new object[] { "PropertyGroup", "Uploadsource", "System.Boolean", false, MappingType.Element });
dtFile.Rows.Add(new object[] { "PropertyGroup", "Sourceextension", "System.String", "cs", MappingType.Element });
dtFile.Rows.Add(new object[] { "PropertyGroup", "Sourcepath", "System.String", "$(MSBuildProjectDirectory)", MappingType.Element });
dtFile.Rows.Add(new object[] { "PropertyGroup", "Usedeployattributes", "System.Boolean", true, MappingType.Element });
dtFile.Rows.Add(new object[] { "PropertyGroup", "Deploydbgsymbols", "System.Boolean", true, MappingType.Element });
dtFile.Rows.Add(new object[] { "PropertyGroup", "Debugpath", "System.String", "$(TargetDir)$(TargetName).pdb", MappingType.Element });
dtFile.Rows.Add(new object[] { "PropertyGroup", "Castudtcolto", "System.Int32", 0, MappingType.Element });
dtFile.Rows.Add(new object[] { "PropertyGroup", "Serverversion", "System.Int32", 0, MappingType.Element });
dtFile.Rows.Add(new object[] { "DeployAssembly", "UsingDMDeployAttributes", "System.String", "$(Usedeployattributes)", MappingType.Attribute });
dtFile.Rows.Add(new object[] { "DeployAssembly", "DeployDebugSymbols", "System.String", "$(Deploydbgsymbols)", MappingType.Attribute });
dtFile.Rows.Add(new object[] { "DeployAssembly", "TypeToCastUDTTo", "System.String", "$(Castudtcolto)", MappingType.Attribute });
dtFile.Rows.Add(new object[] { "DeployAssembly", "SqlServerVersion", "System.String", "$(Serverversion)", MappingType.Attribute });
dtFile.Rows.Add(new object[] { "DeployTypes", "TypeToCastUDTTo", "System.String", "$(Castudtcolto)", MappingType.Attribute });
dtFile.Rows.Add(new object[] { "DropAssembly", "TypeToCastUDTTo", "System.String", "$(Castudtcolto)", MappingType.Attribute });
bool ret = false;
//read off the values and check against the proj-file
foreach (DataRow r in dtFile.Rows)
{
ret = CheckDataSet2(ds, r["TableName"].ToString(), r["ColumnName"].ToString(), r["TypeName"].ToString(), (object)r["ObjectValue"], (MappingType)r["MapType"]);
if (ret)
hasChanges = true;
}
if (hasChanges)
{
ds.AcceptChanges();
DataSet dsUpdate = null;
dsUpdate = ds.Copy();
XmlDataDocument doc = new XmlDataDocument(dsUpdate);
doc.Save(sqlProjPath);
ds.Clear();
ds.Dispose();
}
return hasChanges;
}
示例9: run
//Activate This Construntor to log All To Standard output
//public TestClass():base(true){}
//Activate this constructor to log Failures to a log file
//public TestClass(System.IO.TextWriter tw):base(tw, false){}
//Activate this constructor to log All to a log file
//public TestClass(System.IO.TextWriter tw):base(tw, true){}
//BY DEFAULT LOGGING IS DONE TO THE STANDARD OUTPUT ONLY FOR FAILURES
public void run()
{
Exception exp = null;
//create source dataset
DataSet ds = new DataSet();
DataTable dt = GHTUtils.DataProvider.CreateParentDataTable();
dt.TableName = "Table1";
ds.Tables.Add(dt.Copy());
dt.TableName = "Table2";
//add primary key
dt.PrimaryKey = new DataColumn[] {dt.Columns[0]};
ds.Tables.Add(dt.Copy());
//create target dataset (copy of source dataset)
DataSet dsTarget = ds.Copy();
int iTable1RowsCount = dsTarget.Tables["Table1"].Rows.Count;
//Source - add another table, don't exists on the target dataset
ds.Tables.Add(new DataTable("SomeTable"));
ds.Tables["SomeTable"].Columns.Add("Id");
ds.Tables["SomeTable"].Rows.Add(new object[] {777});
//Target - add another table, don't exists on the source dataset
dsTarget.Tables.Add(new DataTable("SmallTable"));
dsTarget.Tables["SmallTable"].Columns.Add("Id");
dsTarget.Tables["SmallTable"].Rows.Add(new object[] {777});
//update existing row
ds.Tables["Table2"].Select("ParentId=1")[0][1] = "OldValue1";
//add new row
object[] arrAddedRow = new object[] {99,"NewValue1","NewValue2",new DateTime(0),0.5,true};
ds.Tables["Table2"].Rows.Add(arrAddedRow);
//delete existing rows
foreach (DataRow dr in ds.Tables["Table2"].Select("ParentId=2"))
{
dr.Delete();
}
try
{
BeginCase("Merge - changed values");
dsTarget.Merge(ds);
Compare(dsTarget.Tables["Table2"].Select("ParentId=1")[0][1] , "OldValue1");
}
catch(Exception ex) {exp = ex;}
finally {EndCase(exp); exp = null;}
try
{
BeginCase("Merge - added values");
Compare(dsTarget.Tables["Table2"].Select("ParentId=99")[0].ItemArray , arrAddedRow);
}
catch(Exception ex) {exp = ex;}
finally {EndCase(exp); exp = null;}
try
{
BeginCase("Merge - deleted row");
Compare(dsTarget.Tables["Table2"].Select("ParentId=2").Length ,0);
}
catch(Exception ex) {exp = ex;}
finally {EndCase(exp); exp = null;}
//Table1 rows count should be double (no primary key)
try
{
BeginCase("Merge - Unchanged table 1");
Compare(dsTarget.Tables["Table1"].Rows.Count ,iTable1RowsCount * 2);
}
catch(Exception ex) {exp = ex;}
finally {EndCase(exp); exp = null;}
//SmallTable rows count should be the same
try
{
BeginCase("Merge - Unchanged table 2");
Compare(dsTarget.Tables["SmallTable"].Rows.Count ,1);
}
catch(Exception ex) {exp = ex;}
finally {EndCase(exp); exp = null;}
//SomeTable - new table
try
//.........这里部分代码省略.........
示例10: gridViewNgayNghiPhep_ValidateRow
void gridViewNgayNghiPhep_ValidateRow(object sender, DevExpress.XtraGrid.Views.Base.ValidateRowEventArgs e)
{
DataRow row = gridViewNgayNghiPhep.GetDataRow(e.RowHandle);
if (row == null) return;
row.ClearErrors();
ds = (gridControlNgayNghiPhep.DataSource as DataTable).DataSet;
if (!HelpInputData.ValidateRow(gridViewNgayNghiPhep, row, GetRule()))
{
e.Valid = false;
return;
}
if (string.Compare(row["SANG"].ToString(), "Y") != 0 && string.Compare(row["CHIEU"].ToString(), "Y") != 0) {
e.Valid = false;
row.SetColumnError("SANG","Vui lòng vào thông tin \"Sáng\"!");
row.SetColumnError("CHIEU", "Vui lòng vào thông tin \"Chiều\"!");
return;
}
DataSet newDs = new DataSet();
newDs = ds.Copy();
HelpDataSet.MergeDataSet(new string[] { "NGAY" }, newDs, dsforValidate);
if (CheckDuplicate(row, newDs))
{
e.Valid = false;
row.SetColumnError("NGAY", "Thông tin \"Ngày nghỉ phép\" đã được sử dụng!");
return;
}
}
示例11: RejectChanges
[Test] public void RejectChanges()
{
DataSet ds1,ds2 = new DataSet();
ds2.Tables.Add(DataProvider.CreateParentDataTable());
ds1 = ds2.Copy();
//create changes
ds2.Tables[0].Rows[0][0] = "70";
ds2.Tables[0].Rows[1].Delete();
ds2.Tables[0].Rows.Add(new object[] {9,"string1","string2"});
// RejectChanges
ds2.RejectChanges();
Assert.AreEqual(ds2.GetXml(), ds1.GetXml(), "DS345");
}
示例12: Copy
[Test] public void Copy()
{
DataSet ds = new DataSet(), dsTarget = null;
ds.Tables.Add(DataProvider.CreateParentDataTable());
ds.Tables.Add(DataProvider.CreateChildDataTable());
ds.Relations.Add(new DataRelation("myRelation",ds.Tables[0].Columns[0],ds.Tables[1].Columns[0]));
ds.Tables[0].Rows.Add(new object[] {9,"",""});
ds.Tables[1].Columns[2].ReadOnly = true;
ds.Tables[0].PrimaryKey = new DataColumn[] {ds.Tables[0].Columns[0],ds.Tables[0].Columns[1]};
//copy data and schema
// Copy 1
dsTarget = ds.Copy();
//Assert.AreEqual(ds.GetXmlSchema(), dsTarget.GetXmlSchema() , "DS19");
//using my function because GetXmlSchema in not implemented in java
Assert.AreEqual(DataProvider.GetDSSchema(ds), DataProvider.GetDSSchema (dsTarget) , "DS20");
// Copy 2
Assert.AreEqual(true, dsTarget.GetXml() == ds.GetXml(), "DS21");
}
示例13: ReadXml_Strg
public void ReadXml_Strg()
{
string sTempFileName = "tmpDataSet_ReadWriteXml_43894.xml" ;
DataSet ds1 = new DataSet();
ds1.Tables.Add(DataProvider.CreateParentDataTable());
ds1.Tables.Add(DataProvider.CreateChildDataTable());
//add data to check GH bug of DataSet.ReadXml of empty strings
ds1.Tables[1].Rows.Add(new object[] {7,1,string.Empty,string.Empty,new DateTime(2000,1,1,0,0,0,0),35});
ds1.Tables[1].Rows.Add(new object[] {7,2," "," ",new DateTime(2000,1,1,0,0,0,0),35});
ds1.Tables[1].Rows.Add(new object[] {7,3,"","",new DateTime(2000,1,1,0,0,0,0),35});
//write xml file, data only
ds1.WriteXml(sTempFileName);
//copy both data and schema
DataSet ds2 = ds1.Copy();
//clear the data
ds2.Clear();
ds2.ReadXml(sTempFileName);
//check xml data
// ReadXml - Tables count
Assert.AreEqual(ds2.Tables.Count , ds1.Tables.Count , "DS297");
// ReadXml - Table 1 row count
Assert.AreEqual(ds2.Tables[0].Rows.Count, ds1.Tables[0].Rows.Count , "DS298");
// ReadXml - Table 2 row count
Assert.AreEqual(ds2.Tables[1].Rows.Count, ds1.Tables[1].Rows.Count , "DS299");
//try to delete the file
System.IO.File.Delete(sTempFileName);
}
示例14: Merge_RelationWithoutConstraints
public void Merge_RelationWithoutConstraints ()
{
DataSet ds = new DataSet ();
DataTable table1 = ds.Tables.Add ("table1");
DataTable table2 = ds.Tables.Add ("table2");
DataColumn pcol = table1.Columns.Add ("col1", typeof (int));
DataColumn ccol = table2.Columns.Add ("col1", typeof (int));
DataSet ds1 = ds.Copy ();
DataRelation rel = ds1.Relations.Add ("rel1", ds1.Tables[0].Columns[0],
ds1.Tables [1].Columns [0], false);
ds.Merge (ds1);
Assert.AreEqual (1, ds.Relations.Count , "#1");
Assert.AreEqual (0, ds.Tables [0].Constraints.Count , "#2");
Assert.AreEqual (0, ds.Tables [1].Constraints.Count , "#3");
}
示例15: Merge_ByComplexDataSet
[Test] public void Merge_ByComplexDataSet()
{
//create source dataset
DataSet ds = new DataSet();
ds.Tables.Add(DataProvider.CreateParentDataTable());
ds.Tables.Add(DataProvider.CreateChildDataTable());
ds.Tables["Child"].TableName = "Child2";
ds.Tables.Add(DataProvider.CreateChildDataTable());
// Console.WriteLine(ds.Tables[0].TableName + ds.Tables[1].TableName + ds.Tables[2].TableName);
// Console.WriteLine(ds.Tables[2].Rows.Count.ToString());
//craete a target dataset to the merge operation
DataSet dsTarget = ds.Copy();
//craete a second target dataset to the merge operation
DataSet dsTarget1 = ds.Copy();
//------------------ make some changes in the second target dataset schema --------------------
//add primary key
dsTarget1.Tables["Parent"].PrimaryKey = new DataColumn[] {dsTarget1.Tables["Parent"].Columns["ParentId"]};
dsTarget1.Tables["Child"].PrimaryKey = new DataColumn[] {dsTarget1.Tables["Child"].Columns["ParentId"],dsTarget1.Tables["Child"].Columns["ChildId"]};
//add Foreign Key (different name)
dsTarget1.Tables["Child2"].Constraints.Add("Child2_FK_2",dsTarget1.Tables["Parent"].Columns["ParentId"],dsTarget1.Tables["Child2"].Columns["ParentId"]);
//add relation (different name)
//dsTarget1.Relations.Add("Parent_Child_1",dsTarget1.Tables["Parent"].Columns["ParentId"],dsTarget1.Tables["Child"].Columns["ParentId"]);
//------------------ make some changes in the source dataset schema --------------------
//add primary key
ds.Tables["Parent"].PrimaryKey = new DataColumn[] {ds.Tables["Parent"].Columns["ParentId"]};
ds.Tables["Child"].PrimaryKey = new DataColumn[] {ds.Tables["Child"].Columns["ParentId"],ds.Tables["Child"].Columns["ChildId"]};
//unique column
ds.Tables["Parent"].Columns["String2"].Unique = true; //will not be merged
//add Foreign Key
ds.Tables["Child2"].Constraints.Add("Child2_FK",ds.Tables["Parent"].Columns["ParentId"],ds.Tables["Child2"].Columns["ParentId"]);
//add relation
ds.Relations.Add("Parent_Child",ds.Tables["Parent"].Columns["ParentId"],ds.Tables["Child"].Columns["ParentId"]);
//add allow null constraint
ds.Tables["Parent"].Columns["ParentBool"].AllowDBNull = false; //will not be merged
//add Indentity column
ds.Tables["Parent"].Columns.Add("Indentity",typeof(int));
ds.Tables["Parent"].Columns["Indentity"].AutoIncrement = true;
ds.Tables["Parent"].Columns["Indentity"].AutoIncrementStep = 2;
//modify default value
ds.Tables["Child"].Columns["String1"].DefaultValue = "Default"; //will not be merged
//remove column
ds.Tables["Child"].Columns.Remove("String2"); //will not be merged
//-------------------- begin to check ----------------------------------------------
// merge 1 - make sure the merge method invoked without exceptions
dsTarget.Merge(ds);
Assert.AreEqual("Success", "Success", "DS204");
CompareResults_1("merge 1",ds,dsTarget);
//merge again,
// merge 2 - make sure the merge method invoked without exceptions
dsTarget.Merge(ds);
Assert.AreEqual("Success", "Success", "DS205");
CompareResults_1("merge 2",ds,dsTarget);
// merge second dataset - make sure the merge method invoked without exceptions
dsTarget1.Merge(ds);
Assert.AreEqual("Success", "Success", "DS206");
CompareResults_2("merge 3",ds,dsTarget1);
}