本文整理汇总了C#中DataSet.AcceptChanges方法的典型用法代码示例。如果您正苦于以下问题:C# DataSet.AcceptChanges方法的具体用法?C# DataSet.AcceptChanges怎么用?C# DataSet.AcceptChanges使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataSet
的用法示例。
在下文中一共展示了DataSet.AcceptChanges方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AcceptChanges
public void AcceptChanges()
{
var ds = new DataSet();
DataTable dtP = DataProvider.CreateParentDataTable();
DataTable dtC = DataProvider.CreateChildDataTable();
ds.Tables.Add(dtP);
ds.Tables.Add(dtC);
ds.Relations.Add(new DataRelation("myRelation", dtP.Columns[0], dtC.Columns[0]));
//create changes
dtP.Rows[0][0] = "70";
dtP.Rows[1].Delete();
dtP.Rows.Add(new object[] { 9, "string1", "string2" });
// AcceptChanges
ds.AcceptChanges();
Assert.Equal(null, dtP.GetChanges());
//read only exception
dtP.Columns[0].ReadOnly = true;
// check ReadOnlyException
Assert.Throws<ReadOnlyException>(() => dtP.Rows[0][0] = 99);
// check invoke AcceptChanges
ds.AcceptChanges();
}
示例2: Foo
private string Foo(int longIndexName, DataSet ds)
{
string Key = ds.Tables[0].Rows[0]["Key"].ToString();
if (!string.IsNullOrEmpty(Key) && Key != "SAMP")
{
try
{
ds.Tables[0].Rows[0]["Key"] = Encoding.ASCII.GetString(PerfFormOp(Convert.FromBase64String(Key), longIndexName));
ds.AcceptChanges();
}
catch (Exception ex)
{
Logging.Post(ex);
}
}
return ds.GetXml();
}
示例3: Generate
public void Generate()
{
var ds = new DataSet();
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]));
DataRow drParent = ds.Tables[0].Rows[0];
DataRow drChild = ds.Tables[1].Rows[0];
drParent.Delete();
drChild.Delete();
ds.AcceptChanges();
// RowNotInTableException - AcceptChanges
Assert.Throws<RowNotInTableException>(() =>
{
drParent.AcceptChanges();
});
// RowNotInTableException - GetChildRows
Assert.Throws<RowNotInTableException>(() =>
{
drParent.GetChildRows("myRelation");
});
// RowNotInTableException - ItemArray
Assert.Throws<RowNotInTableException>(() => drParent.ItemArray);
// RowNotInTableException - GetParentRows
Assert.Throws<RowNotInTableException>(() => drChild.GetParentRows("myRelation"));
// RowNotInTableException - RejectChanges
Assert.Throws<RowNotInTableException>(() => drParent.RejectChanges());
// RowNotInTableException - SetParentRow
Assert.Throws<RowNotInTableException>(() => drChild.SetParentRow(ds.Tables[0].Rows[1]));
}
示例4: DeserializeModifiedDataSet
public void DeserializeModifiedDataSet()
{
// Serialization begins
DataSet prevDs = new DataSet();
DataTable dt = prevDs.Tables.Add();
dt.Columns.Add(new DataColumn("Id", typeof(string)));
DataRow dr = dt.NewRow();
dr[0] = "a";
dt.Rows.Add(dr);
prevDs.AcceptChanges();
dr = prevDs.Tables[0].Rows[0];
dr[0] = "b";
XmlSerializer serializer = new XmlSerializer(typeof(DataSet));
StringWriter sw = new StringWriter();
XmlTextWriter xw = new XmlTextWriter(sw);
xw.QuoteChar = '\'';
serializer.Serialize(xw, prevDs);
// Deserialization begins
StringReader sr = new StringReader(sw.ToString());
XmlTextReader reader = new XmlTextReader(sr);
XmlSerializer serializer1 = new XmlSerializer(typeof(DataSet));
DataSet ds = serializer1.Deserialize(reader) as DataSet;
Assert.Equal(
prevDs.Tables[0].Rows[0][0, DataRowVersion.Original].ToString(),
ds.Tables[0].Rows[0][0, DataRowVersion.Original].ToString());
Assert.Equal(
prevDs.Tables[0].Rows[0][0, DataRowVersion.Current].ToString(),
ds.Tables[0].Rows[0][0, DataRowVersion.Current].ToString());
}
示例5: WriteXmlModeSchema
//.........这里部分代码省略.........
</xs:keyref>
</xs:element>
</xs:schema>
<Dimension>
<Number>0</Number>
</Dimension>
<Dimension>
<Number>1</Number>
</Dimension>
<Element>
<Dimension>0</Dimension>
<Number>0</Number>
</Element>
<Element>
<Dimension>0</Dimension>
<Number>1</Number>
</Element>
<Element>
<Dimension>0</Dimension>
<Number>2</Number>
</Element>
<Element>
<Dimension>0</Dimension>
<Number>3</Number>
</Element>
<Element>
<Dimension>1</Dimension>
<Number>0</Number>
</Element>
<Element>
<Dimension>1</Dimension>
<Number>1</Number>
</Element>
</Example>";
DataSet ds = new DataSet("Example");
// Dimension DataTable
DataTable dt1 = new DataTable("Dimension");
ds.Tables.Add(dt1);
dt1.Columns.Add(new DataColumn("Number", typeof(int)));
dt1.Columns["Number"].AllowDBNull = false;
dt1.Constraints.Add("PK_Dimension", dt1.Columns["Number"], true);
// Element DataTable
DataTable dt2 = new DataTable("Element");
ds.Tables.Add(dt2);
dt2.Columns.Add(new DataColumn("Dimension", typeof(int)));
dt2.Columns["Dimension"].AllowDBNull = false;
dt2.Columns.Add(new DataColumn("Number", typeof(int)));
dt2.Columns["Number"].AllowDBNull = false;
dt2.Constraints.Add("PK_Element", new DataColumn[] {
dt2.Columns ["Dimension"],
dt2.Columns ["Number"] },
true);
// Add DataRelations
ds.Relations.Add("FK_Element_To_Dimension",
dt1.Columns["Number"],
dt2.Columns["Dimension"], true);
// Add 2 Dimensions
for (int i = 0; i < 2; i++)
{
DataRow newRow = dt1.NewRow();
newRow["Number"] = i;
dt1.Rows.Add(newRow);
}
// Dimension 0 => 4 Elements
for (int i = 0; i < 4; i++)
{
DataRow newRow = dt2.NewRow();
newRow["Dimension"] = 0;
newRow["Number"] = i;
dt2.Rows.Add(newRow);
}
// Dimension 1 => 2 Elements
for (int i = 0; i < 2; i++)
{
DataRow newRow = dt2.NewRow();
newRow["Dimension"] = 1;
newRow["Number"] = i;
dt2.Rows.Add(newRow);
}
ds.AcceptChanges();
StringWriter sw = new StringWriter();
ds.WriteXml(sw, XmlWriteMode.WriteSchema);
string result = sw.ToString();
Assert.Equal(result.Replace("\r\n", "\n"), xml.Replace("\r\n", "\n"));
}
示例6: WriteXmlSchema6
public void WriteXmlSchema6()
{
string xmlschema = @"<?xml version=""1.0"" encoding=""utf-16""?>
<xs:schema id=""Example"" xmlns="""" xmlns:xs=""http://www.w3.org/2001/XMLSchema"" xmlns:msdata=""urn:schemas-microsoft-com:xml-msdata"">
" +
@" <xs:element name=""Example"" msdata:IsDataSet=""true"" msdata:UseCurrentLocale=""true"""
+ @">
<xs:complexType>
<xs:choice minOccurs=""0"" maxOccurs=""unbounded"">
<xs:element name=""MyType"">
<xs:complexType>
<xs:attribute name=""Desc"">
<xs:simpleType>
<xs:restriction base=""xs:string"">
<xs:maxLength value=""32"" />
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>";
DataSet ds = new DataSet("Example");
// Add MyType DataTable
ds.Tables.Add("MyType");
ds.Tables["MyType"].Columns.Add(new DataColumn(
"Desc", typeof(string), "", MappingType.Attribute));
ds.Tables["MyType"].Columns["Desc"].MaxLength = 32;
ds.AcceptChanges();
StringWriter sw = new StringWriter();
ds.WriteXmlSchema(sw);
string result = sw.ToString();
Assert.Equal(result.Replace("\r\n", "\n"), xmlschema.Replace("\r\n", "\n"));
}
示例7: WriteXmlSchema5
public void WriteXmlSchema5()
{
string xmlschema = @"<?xml version=""1.0"" encoding=""utf-16""?>
<xs:schema id=""Example"" xmlns="""" xmlns:xs=""http://www.w3.org/2001/XMLSchema"" xmlns:msdata=""urn:schemas-microsoft-com:xml-msdata"">
" +
" <xs:element name=\"Example\" msdata:IsDataSet=\"true\" msdata:UseCurrentLocale=\"true\""
+ @">
<xs:complexType>
<xs:choice minOccurs=""0"" maxOccurs=""unbounded"">
<xs:element name=""StandAlone"">
<xs:complexType>
<xs:attribute name=""ID"" type=""xs:int"" use=""required"" />
<xs:attribute name=""Desc"" type=""xs:string"" use=""required"" />
</xs:complexType>
</xs:element>
<xs:element name=""Dimension"">
<xs:complexType>
<xs:attribute name=""Number"" msdata:ReadOnly=""true"" type=""xs:int"" use=""required"" />
<xs:attribute name=""Title"" type=""xs:string"" use=""required"" />
</xs:complexType>
</xs:element>
<xs:element name=""Element"">
<xs:complexType>
<xs:attribute name=""Dimension"" msdata:ReadOnly=""true"" type=""xs:int"" use=""required"" />
<xs:attribute name=""Number"" msdata:ReadOnly=""true"" type=""xs:int"" use=""required"" />
<xs:attribute name=""Title"" type=""xs:string"" use=""required"" />
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
<xs:unique name=""PK_Dimension"" msdata:PrimaryKey=""true"">
<xs:selector xpath="".//Dimension"" />
<xs:field xpath=""@Number"" />
</xs:unique>
<xs:unique name=""PK_Element"" msdata:PrimaryKey=""true"">
<xs:selector xpath="".//Element"" />
<xs:field xpath=""@Dimension"" />
<xs:field xpath=""@Number"" />
</xs:unique>
<xs:keyref name=""FK_Element_To_Dimension"" refer=""PK_Dimension"">
<xs:selector xpath="".//Element"" />
<xs:field xpath=""@Dimension"" />
</xs:keyref>
</xs:element>
</xs:schema>";
DataSet ds = new DataSet("Example");
// Add a DataTable with no ReadOnly columns
DataTable dt1 = new DataTable("StandAlone");
ds.Tables.Add(dt1);
// Add a ReadOnly column
dt1.Columns.Add(new DataColumn("ID", typeof(int), "",
MappingType.Attribute));
dt1.Columns["ID"].AllowDBNull = false;
dt1.Columns.Add(new DataColumn("Desc", typeof
(string), "", MappingType.Attribute));
dt1.Columns["Desc"].AllowDBNull = false;
// Add related DataTables with ReadOnly columns
DataTable dt2 = new DataTable("Dimension");
ds.Tables.Add(dt2);
dt2.Columns.Add(new DataColumn("Number", typeof
(int), "", MappingType.Attribute));
dt2.Columns["Number"].AllowDBNull = false;
dt2.Columns["Number"].ReadOnly = true;
dt2.Columns.Add(new DataColumn("Title", typeof
(string), "", MappingType.Attribute));
dt2.Columns["Title"].AllowDBNull = false;
dt2.Constraints.Add("PK_Dimension", dt2.Columns["Number"], true);
DataTable dt3 = new DataTable("Element");
ds.Tables.Add(dt3);
dt3.Columns.Add(new DataColumn("Dimension", typeof
(int), "", MappingType.Attribute));
dt3.Columns["Dimension"].AllowDBNull = false;
dt3.Columns["Dimension"].ReadOnly = true;
dt3.Columns.Add(new DataColumn("Number", typeof
(int), "", MappingType.Attribute));
dt3.Columns["Number"].AllowDBNull = false;
dt3.Columns["Number"].ReadOnly = true;
dt3.Columns.Add(new DataColumn("Title", typeof
(string), "", MappingType.Attribute));
dt3.Columns["Title"].AllowDBNull = false;
dt3.Constraints.Add("PK_Element", new DataColumn[] {
dt3.Columns ["Dimension"],
dt3.Columns ["Number"] }, true);
ds.Relations.Add("FK_Element_To_Dimension",
dt2.Columns["Number"], dt3.Columns["Dimension"]);
ds.AcceptChanges();
//.........这里部分代码省略.........
示例8: WriteXmlSchema4
public void WriteXmlSchema4()
{
string xmlschema = @"<?xml version=""1.0"" encoding=""utf-16""?>
<xs:schema id=""Example"" xmlns="""" xmlns:xs=""http://www.w3.org/2001/XMLSchema"" xmlns:msdata=""urn:schemas-microsoft-com:xml-msdata"">
";
xmlschema = xmlschema + " <xs:element name=\"Example\" msdata:IsDataSet=\"true\" msdata:UseCurrentLocale=\"true\"";
xmlschema = xmlschema + @">
<xs:complexType>
<xs:choice minOccurs=""0"" maxOccurs=""unbounded"">
<xs:element name=""MyType"">
<xs:complexType>
<xs:attribute name=""ID"" type=""xs:int"" use=""required"" />
<xs:attribute name=""Desc"" type=""xs:string"" />
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>";
DataSet ds = new DataSet("Example");
// Add MyType DataTable
DataTable dt = new DataTable("MyType");
ds.Tables.Add(dt);
dt.Columns.Add(new DataColumn("ID", typeof(int), "",
MappingType.Attribute));
dt.Columns["ID"].AllowDBNull = false;
dt.Columns.Add(new DataColumn("Desc", typeof
(string), "", MappingType.Attribute));
ds.AcceptChanges();
StringWriter sw = new StringWriter();
ds.WriteXmlSchema(sw);
string result = sw.ToString();
Assert.Equal(result.Replace("\r\n", "\n"), xmlschema.Replace("\r\n", "\n"));
}
示例9: UpdateDataset
/// <summary>
/// Executes the respective command for each inserted, updated, or deleted row in the DataSet.
/// </summary>
/// <remarks>
/// e.g.:
/// UpdateDataset(conn, insertCommand, deleteCommand, updateCommand, dataSet, "Order");
/// </remarks>
/// <param name="insertCommand">A valid SQL statement to insert new records into the data source</param>
/// <param name="deleteCommand">A valid SQL statement to delete records from the data source</param>
/// <param name="updateCommand">A valid SQL statement used to update records in the data source</param>
/// <param name="dataSet">The DataSet used to update the data source</param>
/// <param name="tableName">The DataTable used to update the data source.</param>
public static void UpdateDataset(SQLiteCommand insertCommand, SQLiteCommand deleteCommand, SQLiteCommand updateCommand, DataSet dataSet, string tableName)
{
if (insertCommand == null) throw new ArgumentNullException("insertCommand");
if (deleteCommand == null) throw new ArgumentNullException("deleteCommand");
if (updateCommand == null) throw new ArgumentNullException("updateCommand");
if (tableName == null || tableName.Length == 0) throw new ArgumentNullException("tableName");
// Create a SQLiteDataAdapter, and dispose of it after we are done
using (SQLiteDataAdapter dataAdapter = new SQLiteDataAdapter())
{
// Set the data adapter commands
dataAdapter.UpdateCommand = updateCommand;
dataAdapter.InsertCommand = insertCommand;
dataAdapter.DeleteCommand = deleteCommand;
// Update the dataset changes in the data source
dataAdapter.Update(dataSet, tableName);
// Commit all the changes made to the DataSet
dataSet.AcceptChanges();
}
}
示例10: SerializeDataSet2
public void SerializeDataSet2()
{
DataSet quota = new DataSet("Quota");
// Dimension
DataTable dt = new DataTable("Dimension");
quota.Tables.Add(dt);
dt.Columns.Add("Number", typeof(int));
dt.Columns["Number"].AllowDBNull = false;
dt.Columns["Number"].ColumnMapping = MappingType.Attribute;
dt.Columns.Add("Title", typeof(string));
dt.Columns["Title"].AllowDBNull = false;
dt.Columns["Title"].ColumnMapping =
MappingType.Attribute;
dt.Rows.Add(new object[] { 0, "Hospitals" });
dt.Rows.Add(new object[] { 1, "Doctors" });
dt.Constraints.Add("PK_Dimension", dt.Columns["Number"], true);
quota.AcceptChanges();
XmlSerializer ser = new XmlSerializer(quota.GetType());
StringWriter sw = new StringWriter();
ser.Serialize(sw, quota);
DataSet ds = (DataSet)ser.Deserialize(new StringReader(sw.ToString()));
}
示例11: AsDataSet
public DataSet AsDataSet(bool convertOADateTime) {
if (!m_isValid)
return null;
if (m_isClosed)
return m_workbookData;
ConvertOaDate=convertOADateTime;
m_workbookData=new DataSet();
for (int index=0; index<ResultsCount; index++) {
DataTable table=readWholeWorkSheet(m_sheets[index]);
if (null!=table)
m_workbookData.Tables.Add(table);
}
m_file.Dispose();
m_isClosed=true;
m_workbookData.AcceptChanges();
m_workbookData.FixDataTypes();
return m_workbookData;
}
示例12: Test2
public void Test2()
{
DataSet RegionDS = new DataSet();
DataRow RegionRow;
RegionDS.ReadXmlSchema(new StringReader(RegionXsd));
Assert.Equal(1, RegionDS.Tables.Count);
XmlDataDocument DataDoc = new XmlDataDocument(RegionDS);
DataDoc.Load(new StringReader(RegionXml));
RegionRow = RegionDS.Tables[0].Rows[0];
RegionDS.AcceptChanges();
RegionRow["RegionDescription"] = "Reeeeeaalllly Far East!";
RegionDS.AcceptChanges();
TextWriter text = new StringWriter();
text.NewLine = "\n";
DataDoc.Save(text);
string TextString = text.ToString();
string substring = TextString.Substring(0, TextString.IndexOf(s_EOL));
TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length);
//Assert.Equal ("<?xml version=\"1.0\" encoding=\"utf-16\" standalone=\"yes\"?>", substring);
substring = TextString.Substring(0, TextString.IndexOf(s_EOL));
TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length);
Assert.Equal("<Root>", substring);
substring = TextString.Substring(0, TextString.IndexOf(s_EOL));
TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length);
Assert.True(substring.IndexOf(" <Region>") != -1);
substring = TextString.Substring(0, TextString.IndexOf(s_EOL));
TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length);
Assert.True(substring.IndexOf(" <RegionID>1</RegionID>") != -1);
substring = TextString.Substring(0, TextString.IndexOf(s_EOL));
TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length);
Assert.Equal(" <RegionDescription>Reeeeeaalllly Far East!</RegionDescription>", substring);
substring = TextString.Substring(0, TextString.IndexOf(s_EOL));
TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length);
Assert.True(substring.IndexOf(" </Region>") != -1);
substring = TextString.Substring(0, TextString.IndexOf(s_EOL));
TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length);
Assert.True(substring.IndexOf(" <Region>") != -1);
substring = TextString.Substring(0, TextString.IndexOf(s_EOL));
TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length);
Assert.True(substring.IndexOf(" <RegionID>2</RegionID>") != -1);
substring = TextString.Substring(0, TextString.IndexOf(s_EOL));
TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length);
Assert.True(substring.IndexOf(" <RegionDescription>Western") != -1);
substring = TextString.Substring(0, TextString.IndexOf(s_EOL));
TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length);
Assert.True(substring.IndexOf(" </RegionDescription>") != -1);
substring = TextString.Substring(0, TextString.IndexOf(s_EOL));
TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length);
Assert.True(substring.IndexOf(" </Region>") != -1);
substring = TextString.Substring(0, TextString.IndexOf(s_EOL));
TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length);
Assert.True(substring.IndexOf(" <Region>") != -1);
substring = TextString.Substring(0, TextString.IndexOf(s_EOL));
TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length);
Assert.True(substring.IndexOf(" <RegionID>3</RegionID>") != -1);
substring = TextString.Substring(0, TextString.IndexOf(s_EOL));
TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length);
Assert.True(substring.IndexOf(" <RegionDescription>Northern") != -1);
substring = TextString.Substring(0, TextString.IndexOf(s_EOL));
TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length);
Assert.True(substring.IndexOf(" </RegionDescription>") != -1);
substring = TextString.Substring(0, TextString.IndexOf(s_EOL));
TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length);
Assert.True(substring.IndexOf(" </Region>") != -1);
substring = TextString.Substring(0, TextString.IndexOf(s_EOL));
TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length);
Assert.True(substring.IndexOf(" <Region>") != -1);
substring = TextString.Substring(0, TextString.IndexOf(s_EOL));
TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length);
Assert.True(substring.IndexOf(" <RegionID>4</RegionID>") != -1);
substring = TextString.Substring(0, TextString.IndexOf(s_EOL));
TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length);
Assert.True(substring.IndexOf(" <RegionDescription>Southern") != -1);
substring = TextString.Substring(0, TextString.IndexOf(s_EOL));
TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length);
Assert.True(substring.IndexOf(" </RegionDescription>") != -1);
//.........这里部分代码省略.........
示例13: ReadDataSet
private DataSet ReadDataSet() {
var dataset = new DataSet();
Dictionary<int, XlsxDimension> demensionDict = DetectDemension();
for (int sheetIndex = 0; sheetIndex < m_workbook.Sheets.Count; sheetIndex++) {
XlsxWorksheet sheet = m_workbook.Sheets[sheetIndex];
var table = new DataTable(m_workbook.Sheets[sheetIndex].Name);
ReadSheetGlobals(sheet);
sheet.Dimension = demensionDict[sheetIndex];
if (sheet.Dimension == null) {
continue;
}
m_depth = 0;
m_emptyRowCount = 0;
// Reada Columns
if (!m_isFirstRowAsColumnNames) {
// No Sheet Columns
for (int i = 0; i < sheet.ColumnsCount; i++) {
table.Columns.Add(i.ToString(CultureInfo.InvariantCulture), typeof(Object));
}
} else if (ReadSheetRow(sheet)) {
// Read Sheet Columns
Debug.Assert(m_cellsValues!=null);
for (int index = 0; index < m_cellsValues.Length; index++) {
if (m_cellsValues[index] != null && m_cellsValues[index].ToString().Length > 0) {
table.AddColumnHandleDuplicate(m_cellsValues[index].ToString());
} else {
table.AddColumnHandleDuplicate(string.Concat(COLUMN, index));
}
}
} else {
continue;
}
// Read Sheet Rows
table.BeginLoadData();
while (ReadSheetRow(sheet)) {
table.Rows.Add(m_cellsValues);
}
if (table.Rows.Count > 0) {
dataset.Tables.Add(table);
}
// Read HyperLinks
ReadHyperLinks(sheet, table);
table.EndLoadData();
}
dataset.AcceptChanges();
dataset.FixDataTypes();
return dataset;
}
示例14: RowStateFilter_2
public void RowStateFilter_2()
{
DataSet dataset = new DataSet("new");
DataTable dt = new DataTable("table1");
dataset.Tables.Add(dt);
dt.Columns.Add("col1");
dt.Columns.Add("col2");
dt.Rows.Add(new object[] { 1, 1 });
dt.Rows.Add(new object[] { 1, 2 });
dt.Rows.Add(new object[] { 1, 3 });
dataset.AcceptChanges();
DataView dataView = new DataView(dataset.Tables[0]);
// 'new' table in this sample contains 6 records
dataView.AllowEdit = true;
dataView.AllowDelete = true;
string v;
// Editing the row
dataView[0]["col1"] = -1;
dataView.RowStateFilter = DataViewRowState.ModifiedOriginal;
v = dataView[0][0].ToString();
Assert.Equal(1, dataView.Count);
Assert.Equal("1", v);
// Deleting the row
dataView.Delete(0);
dataView.RowStateFilter = DataViewRowState.Deleted;
v = dataView[0][0].ToString();
Assert.Equal(1, dataView.Count);
Assert.Equal("1", v);
}
示例15: ForeignKey_650402
// https://bugzilla.novell.com/show_bug.cgi?id=650402
public void ForeignKey_650402()
{
DataSet data = new DataSet();
DataTable parent = new DataTable("parent");
DataColumn pk = parent.Columns.Add("PK");
DataTable child = new DataTable("child");
DataColumn fk = child.Columns.Add("FK");
data.Tables.Add(parent);
data.Tables.Add(child);
data.Relations.Add(pk, fk);
parent.Rows.Add("value");
child.Rows.Add("value");
data.AcceptChanges();
child.Rows[0].Delete();
parent.Rows[0][0] = "value2";
data.EnforceConstraints = false;
data.EnforceConstraints = true;
}