Parser Query

Anwind

Well-known member
Joined
Nov 6, 2021
Messages
48
Programming Experience
1-3
file.png


Lumenworks

CsvReader reader = new CsvReader(new StreamReader(D:₩₩file.csv), true):
 
Last edited:
Unfortunately the Lumenworks CsvReader doesn't support passing in a query. So what you want:
Just apply the query statement to CsvReader.
is not possible.

You'll need to write your code to do the filtering, sorting, and transforms, and then expose that as an IDataReader.
 
Yes.
 
C#:
// create a static class
public static class DataReaderExtension
{
    public static IEnumerable<Dictionary<string, object>> AsEnumerable(this System.Data.IDataReader source)
    {
        if (source == null)
            throw new ArgumentNullException("source");

        while (source.Read())
        {
            Dictionary<string, object> row = new Dictionary<string, object>();
            for (int i = 0; i < source.FieldCount; i++)
            {
                object value = source.GetValue(i);
        // return an empty string for dbnull value of field type string
                if (source.GetFieldType(i) == typeof(string) && source.IsDBNull(i))
                    value = string.Empty;
                row.Add(source.GetName(i), value);
            }
            yield return row;
        }
    }
}

// suppose you have a class named MYBooks with properties names ID (int) and TITLE (string)
// and the datareader contains more records with two fileds named ID_BOOK and TITLE

myDataReader.AsEnumerable().Select(i => new MYBooks()
{
    ID = (int)i["ID_BOOK"],
    TITLE = (string)i["TITLE"]
});


Is this example code correct?
 
What does your testing show?
 
I thought that you agreed not to delete previous posts. *sigh*

You need to understand that this forum is a regular chronological forum. This in not like StackOverflow where answers come in any order, and people are expected to massage their original questions as comments come in to try to help a write a better question or a better answer. With a regular forum, it is like a series of email messages.
 
Back
Top Bottom