资源简介
c#操作txt的类库总结 包含写入txt、读取txt、读取指定行、删除指定行、查询txt指定内容 给定条件查询、删除文件以及递归删除文件等功能
代码片段和文件信息
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DBHelperCommon.FilesHelper
{
public class TXTHelper
{
#region DataTable_Select
///
/// 按照指定条件对DataTable内容进行查询,查询结果以DataTable形式返回。
///
/// 待查询DataTable
/// 查询条件(例如condition=“c0=‘0‘ and c1=‘2‘“)
///
public DataTable DataTable_Select(DataTable dt string condition)
{
DataTable table = new DataTable();
try
{
DataRow[] rowArray = dt.Select(condition);
DataRow[] rowArray2 = rowArray;
table = dt.Clone();
if (rowArray.Length <= 0)
{
return table;
}
for (int i = 0; i < rowArray.Length; i++)
{
table.Rows.Add(rowArray2[i].ItemArray);
}
table.AcceptChanges();
}
catch (Exception exception)
{
string text = exception.ToString();
if (exception.InnerException != null)
{
text = text + exception.InnerException.ToString();
}
if (exception.StackTrace != null)
{
text = text + exception.StackTrace.ToString();
}
//
}
return table;
}
///
/// 按照指定条件对DataTable内容进行查询,查询结果以DataTable形式返回。
///
/// 待查询DataTable
/// 查询条件1(例如condition=“c0=‘0‘ and c1=‘2‘“)
/// 查询条件2该条件为排序条件(例如ordercondition=“c1 desc“)
///
public DataTable DataTable_Select(DataTable dt string condition string ordercondition)
{
DataTable table = new DataTable();
try
{
DataRow[] rowArray = dt.Select(condition ordercondition);
table = dt.Clone();
if (rowArray.Length <= 0)
{
return table;
}
for (int i = 0; i < rowArray.Length; i++)
{
table.Rows.Add(rowArray[i].ItemArray);
}
table.AcceptChanges();
}
catch (Exception exception)
{
string text = exception.ToString();
if (exception.InnerException != null)
{
text = text + exception.InnerException.ToString();
}
if (exception.StackTrace
评论
共有 条评论