通过条件查询并排序得到新的DT
string clumname = "";
string filtcontext = "";
string wherecode = clumname + "='" + filtcontext + "'";
/// <summary>
/// 通过条件查询并排序得到新的DT
/// </summary>
/// <param name="dt">源DT</param>
/// <param name="wherecode">查询条件</param>
/// <param name="orderby">排序</param>
/// <returns>根据给定的DT生成新的DT</returns>
public static DataTable ScreeningDataTable(DataTable dt, string wherecode, string orderby)
{
DataTable newdt = new DataTable();
newdt = dt.Clone();
DataRow[] dr = dt.Select(wherecode, orderby);
for (int i = 0; i < dr.Length; i++)
{
newdt.ImportRow((DataRow)dr[i]);
}
return newdt;//返回的查询结果
}
通过条件查询得到新的DT
/// <summary>
/// 通过条件查询得到新的DT
/// </summary>
/// <param name="dt">源DT</param>
/// <param name="wherecode">查询条件</param>
/// <returns>根据给定的DT生成新的DT</returns>
public static DataTable ScreeningDataTable(DataTable dt, string wherecode)
{
DataTable newdt = new DataTable();
newdt = dt.Clone();
DataRow[] dr = dt.Select(wherecode);
for (int i = 0; i < dr.Length; i++)
{
newdt.ImportRow((DataRow)dr[i]);
}
return newdt;//返回的查询结果
}
统计DataTable中某一列不同值
DataTable dtyouliao = new DataTable();
//统计DataTable中某一列不同值 筛选车号不重复值
DataView dtview = dtyouliao.DefaultView;
DataTable dtTemporary = new DataTable();//车号dt
dtTemporary = dtview.ToTable(true, "车号");
dataGridView1.DataSource = dtTemporary;
打开文件夹并遍历所有.xls* 的内容
FolderBrowserDialog dialog = new FolderBrowserDialog();
dialog.ShowNewFolderButton = false;
dialog.Description = "请选择文件路径";
if (defaultfilePath != "")
{
//设置此次默认目录为上一次选中目录
dialog.SelectedPath = defaultfilePath;
}
DialogResult result = dialog.ShowDialog();
if (result == DialogResult.OK || result == DialogResult.Yes)
{
string foldPath = dialog.SelectedPath;
defaultfilePath = foldPath;
string[] files = Directory.GetFiles(defaultfilePath + @"\", "*.xls*");
foreach (string file in files)
{
// MessageBox.Show(file);
string currPath = file.Substring(0, file.LastIndexOf(@"\"));
string excelname = file.Substring(file.LastIndexOf(@"\") + 1, file.LastIndexOf(@".xls") - file.LastIndexOf(@"\") - 1);
DataTable dtinput = new DataTable();
dtinput = NPOI_Excel.ExcelToDataTable(file, true, 3);
dtinput.TableName = excelname;
dtsdanxiangkaoke.Add(dtinput);
}
}
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。