我想从目录中检索文本文件数据到 sql 中的特定数据库字段。这是一个代码:
try
{
FolderBrowserDialog fBrowser = new FolderBrowserDialog();
//create instance of folder browser to navigate to desired folder to compress files
DialogResult result = fBrowser.ShowDialog();
//process this if user clicks OK button
if (result == DialogResult.OK)
{
//string strPath stores chosen path
strPath = fBrowser.SelectedPath;
//put that path in the textbox1
txtSource.Text = strPath;
}
//set current directory to be the one you navigated to
//(this is also the folder that will store the compressed file)
Directory.SetCurrentDirectory(strPath);
//get contents of directory stored in "strPath"
DirectoryInfo di = new DirectoryInfo(strPath);
//create array that holds requested files from folder stored in "di" variable
DirectoryInfo[] rgFiles = di.GetDirectories("*.*");
//move through DirectoryInfo array and store in new array of fi
foreach (DirectoryInfo fi in rgFiles)
{
checkedListBox1.Items.Add(fi.Name); //add folders located into listbox
}
}
这里的目录不包含。对于图像和 txt 文件,如果我们选择复选框,则 txt 文件中的所有数据都应添加到与其数据类型相关的特定 sql 数据库中。谁能帮我吗