0

I am using some Sybase query reader but can't find anyway so far to load the data using the column names instead of the column number. Would you know how to? Here is my current reader that I'd like to change:

var queryReader = TheContext.ExecuteStoredProcedure("dbo.sp_getMyData");
try
{
    while (queryReader.Read())
    {
        if (queryReader.GetValue(0) == null) { continue; }
        int numDaysPending; int.TryParse(queryReader.GetValue(2).ToString(), out numDaysPending);
        ...

thank you!

goul
  • 813
  • 1
  • 13
  • 32
  • You may want to add more context, and better tags for more visibility. Clarify what language you are using, specific error messages..anything else that could help someone determine what issue you are having. – Mike Gardner Jul 23 '13 at 02:05

1 Answers1

0

I've found the answer, just needed to generate some dictionnary containing the columns mappings [columnName;columnId]:

public Dictionary<String, int> GetColumnsMap(AseDataReader reader)
{
    var columnCount = reader.FieldCount;
    Dictionary<String, int> columnsMap = new Dictionary<String, int>();
    for (int columnId = 0; columnId < columnCount; columnId++)
    {
        var columnName = reader.GetName(columnId);
        if (!columnsMap.ContainsKey(columnName))
        {
            columnsMap.Add(columnName, columnId);
        }
    }
    return columnsMap;
}

Usage:

brand = columnsMap["Brands"]
goul
  • 813
  • 1
  • 13
  • 32