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!

4

1 回答 1

0

我找到了答案,只需要生成一些包含列映射 [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;
}

用法:

brand = columnsMap["Brands"]
于 2013-08-14T02:43:27.583 回答