3 Replies - 431 Views - Last Post: 27 January 2013 - 12:40 PM Rate Topic: -----

#1 kevin_mchugh  Icon User is offline

  • D.I.C Head

Reputation: 11
  • View blog
  • Posts: 70
  • Joined: 08-April 09

Selecting from on Datatable in memoy into another.

Posted 27 January 2013 - 10:37 AM

I am almost 100% positive I cannot do what I want with this particular piece of code but I thought I would ask for either A)Suggestions on an alternative approach of B)Someone to say "Well actually you could......".

Basically I am writing a class/program to allow you to interrogate a file structure using SQL. I don't know if there are already programs out there that already do that but we where discussing at work how nice it would be if we could do something like that. So I wrote the following:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;


namespace FileQuery
{
    class FileQueryer
    {
        private System.Data.DataTable _source;
        private System.Data.DataTable _results;

        public void FileQuery()
        {
            _source = new System.Data.DataTable();
            _results = new System.Data.DataTable();
        }

        public System.Data.DataTable DisplayResult()
        {
            return this._results;
        }
        
        public void ReadDirectory(String root)
        {
            DirectoryInfo files = new DirectoryInfo(root);
            
                foreach (FileInfo file in files.GetFiles())
                {
                    _source.Rows.Add(file.FullName, file.Extension, file.Name, file.Length);
                }
        }

        public void QueryDirectory(String query)
        {
            //Select from _source into _results
        }
    }
}




Now I foolishly thought that it would be quite easy to run a Select query on one Datatable stored in memory and pop the results into another. Without having to write either to a database. Turns out their isn't....or at least none that I could find. So I am looking for alternatives or a something to say I was wrong about being wrong.

I am not looking for full code or solutions just a nudge in the write direction. Otherwise I am actually quite pleased with this simple little application.

Thanks for all the help and apologies if this is in the wrong place.

Kevin

Is This A Good Question/Topic? 0
  • +

Replies To: Selecting from on Datatable in memoy into another.

#2 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3646
  • View blog
  • Posts: 11,412
  • Joined: 05-May 12

Re: Selecting from on Datatable in memoy into another.

Posted 27 January 2013 - 11:14 AM

So where are your attempts? Looks like you just put together the out facing interface/class methods but have not actually attempted anything.

Have you even looked at the Select() and LoadDataRow() methods of the DataTable?

But to answer your generic question about whether it is possible to interrogate a file structure using SQL. If you loosened it from SQL to SQL-like, then yes, you can. Consider the WMI interfaces which lets you do this, as well as, the current crop of LINQ-to-Foo methods. If you can expose your file structure as an IEnumerable, even standard LINQ on IEnumerable will give you what you need.

This post has been edited by Skydiver: 27 January 2013 - 11:18 AM

Was This Post Helpful? 1
  • +
  • -

#3 kevin_mchugh  Icon User is offline

  • D.I.C Head

Reputation: 11
  • View blog
  • Posts: 70
  • Joined: 08-April 09

Re: Selecting from on Datatable in memoy into another.

Posted 27 January 2013 - 12:01 PM

View PostSkydiver, on 27 January 2013 - 11:14 AM, said:

So where are your attempts? Looks like you just put together the out facing interface/class methods but have not actually attempted anything.

Have you even looked at the Select() and LoadDataRow() methods of the DataTable?

But to answer your generic question about whether it is possible to interrogate a file structure using SQL. If you loosened it from SQL to SQL-like, then yes, you can. Consider the WMI interfaces which lets you do this, as well as, the current crop of LINQ-to-Foo methods. If you can expose your file structure as an IEnumerable, even standard LINQ on IEnumerable will give you what you need.


Honestly I just left the failed attempts off. I didn't think they where any good to man nor beast. The where failed implementations of:

_result = _source.select(query);



Thanks for the advice though much appreciated.
Was This Post Helpful? 0
  • +
  • -

#4 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3646
  • View blog
  • Posts: 11,412
  • Joined: 05-May 12

Re: Selecting from on Datatable in memoy into another.

Posted 27 January 2013 - 12:40 PM

Well, that obviously won't work because Select() returns an array of DataRow's but you are trying to assign to a DataTable. Hence my suggestion of looking at LoadDataRow().

Sent from my T-Mobile G2 using Tapatalk 2
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1