1

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!

4
  • A Dataset is a table container; if there is only one table in the dataset then Datatable dt =myDataSet.tables[0]; will return the table your are expecting Commented Jul 25, 2012 at 23:56
  • I'm not sure that will work... The Dataset contains three different tables: DistributionPoints PackageDB PackageDB_Query(This is the table I need to reference) Thank you for replying though! Commented Jul 26, 2012 at 0:50
  • Does your SQL DataSet returning data with table names? If yes, it would be easy to fetch PackageName based on PackageID from that specific table. If not, means you don't know in which table (appearently on what Index in DataSet) the Package information is. In this case, you have to check each table in DataSet and find out the package name. Let me know if this makes sense. I will provide the code then. Commented Jul 26, 2012 at 3:19
  • The error you're getting means that there is no row in the DataTable with the PackageID you're looking for. Your code starts with ds = new PackageDBDataSet() which produces an empty DataSet. You am taking that you have code to load a populated DataSet from the database? Commented Jul 27, 2012 at 0:32

1 Answer 1

1

Should be something along those lines:

using System.Linq;
...

DataSet ds = GetDataSet();
DataTable dt = ds.Tables["PackageDB_Query"];
DataRow dr = dt.Rows.Cast<DataRow>().Single(row => row["PackageID"] == dir);

string packageName = dr["PackageName"];
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for all the help... Sometimes I over think this stuff!
I have made edits to the code based on your suggestion and it still doesnt't work! Here is my function:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.