将数据库中的文件名与目录列表进行比较 [英] Compare File names in database with directory list
本文介绍了将数据库中的文件名与目录列表进行比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想比较数据库中的文件名,并将其与目录列表中的文件名进行比较.
我已经成功地从数据库中过滤掉了文件名,但是现在我陷入了如何将其与目录列表文件名进行比较的问题.
如果名称匹配,那么我要在复选框列表中显示文件..
我已经用这段代码开始了……
I want to compare the file names from the database and compare that names with the file name present in the directory list.
I have successfully filter out the file names from the database but now I am stuck on how to compare it with the directory list file name.
If the names matche, then I want to display the file in the checkboxlist..
I have started it with this code......
SqlConnection sqlCon = new SqlConnection("Server=FNUEXCPC01\\SQLSERVER2005;Database=PREMIUM;Trusted_Connection=yes;");
sqlCon.Open();
//sqlCmd.Connection = sqlCon;
//SqlDataReader myReader;
string sql = "Select Ref_Link from RECORDSMG where Department = '" + ddview.SelectedValue + "'and School= '"
+ ddlistschools.SelectedValue + "' and Doc_Category = '" + ddcat.SelectedValue + "'";
SqlCommand sqlCmd = new SqlCommand();
sqlCmd.Connection = sqlCon;
sqlCmd.CommandType = CommandType.Text;
sqlCmd.CommandText = sql;
SqlDataReader myReader = sqlCmd.ExecuteReader();
while (myReader.Read())
{
// returnValue.Add(myReader.GetString(0));
//chkAdd(myReader.GetString(1));
chk.Items.Add(myReader.GetString(0));
var test2 = myReader;
//var test = chk;
// Response.Write(test);
}
推荐答案
我将从数据库中将它们读取到一个列表中,并对其进行排序(或使用Sql ORDER BY子句为您完成此操作) .
然后,您可以使用以下方法读取文件夹内容:
I would read them from the database into a list, and sort it (or use the Sql ORDER BY clause to do that for you).
You can then read the folder content using:
string[] files = Directory.GetFiles(path,searchPattern,SearchOption.TopDirectoryOnly)
如果将它们排序到与数据库列表的顺序相同,比较它们是相对简单的事情.
If you then sort these into the same order as the database list, it is a relatively simple matter to compare them.
这篇关于将数据库中的文件名与目录列表进行比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文