Using system;
Using system. Collections. Generic;
Using system. text;
Using system. Data;
Using system. Data. sqlclient;
Using Microsoft. Office. InterOP. Excel;
Using Microsoft. Office. InterOP. word;
Using system. collections;
Using system. IO;
Namespace common
{
Public class datasetoperation
{
String exceptionmessage; // defines the exception information.
Datasetoperation ()
{
}
# Region connects two able with the same data structure and returns the datatable
/// <Summary>
/// Connect two able with the same data structure and return the datatable
/// </Summary>
/// <Param name = "Table1"> </param>
/// <Param name = "Table2"> </param>
/// <Returns> </returns>
Public System. Data. datatable getinnerdatatable (system. Data. datatable Table1, system. Data. datatable table2)
{
Table1.merge (table2 );
Return Table1;
}
// Write the dataset to an XML file
Public bool writedatasettoxml (Dataset dataset, string filename)
{
Try
{
Dataset. writexml (filename );
Return true;
}
Catch (exception ex)
{
Predictionmessage = ex. message;
Return false;
}
}
# Endregion
# Region Query data in a datatable
/// <Summary>
/// Query the data in the datatable
/// </Summary>
/// <Param name = "table"> datatable to be queried </param>
/// <Param name = "comtext"> query condition </param>
/// <Returns> data column set </returns>
Public datarow [] getselectdatatable (system. Data. datatable table, string comtext)
{
Try
{
Datarow [] rows = table. Select (comtext );
Return rows;
}
Catch (exception ex)
{
Predictionmessage = ex. message;
Return NULL;
}
}
# Endregion
# Region setting or getting exception information
/// <Summary>
/// Set or obtain exception information
/// </Summary>
Public String exceptionmessage
{
Get
{
Return exceptionmessage;
}
Set
{
Predictionmessage = value;
}
}
# Endregion
}
}
Note:ArticleReprinted to Bai yixuan