I'm trying to create a program that scans our corporate distribution points and will use the package data that I have exported from SCCM.
I currently have a SQL Data-set connected to Visual Studio as a Data Source and also a string array the runs through the Directory and fills a list view.
The Dataset contain 3 Tables and the one I want to use is called PackageDB_Query:
The Column in this Table are:
- PackageName
- Manufacturer
- Description
- Version
- Language
- PackageID (This is the name of the folder on the server(ex. FMC00015A)
I would compare the directory name to the PackageID in the Dataset and return the Package name.
Here is the function I use to fill the listview with the folder names:
`public void FolderScan()
{
try
{
string[] dirs = Directory.GetDirectories("\\" + _serverName + "\\" + _commonShareName, "FMC*");
folderCntBox.Text = dirs.Length.ToString();
foreach (string dir in dirs)
{
listBox1.Items.Add(dir);
}
}
catch (Exception ex)
{
Console.WriteLine(Resources.MainForm_FolderScan_The_process_failed___0_, ex);
}
}`
I have made edits to the code based on the suggestions below and it still doesn't work! Here is my function:
'private void FolderScanTest()
{
try
{
var ds = new PackageDBDataSet();
var dt = ds.Tables["PackageDB_Query"];
string[] dirs = Directory.GetDirectories(@"\\PLYMMIMS001\SMSPKGD$", "FMC*");
folderCntBox.Text = dirs.Length.ToString(CultureInfo.InvariantCulture);
foreach (string dir in dirs)
{
DataRow dr = dt.Rows.Cast<DataRow>().Single(row => row["PackageID"] == dir);
var packageName = dr["PackageName"] as string;
listBox1.Items.Add(packageName);
}
}
catch (Exception ex)
{
MessageBox.Show(Resources.MainForm_FolderScan_The_process_failed___0_ + ":" + ex, "Error");
}
}'
It says the sequence contains no matching element!
Datatable dt =myDataSet.tables[0];will return the table your are expectingds = new PackageDBDataSet()which produces an empty DataSet. You am taking that you have code to load a populated DataSet from the database?