Idatareader string values

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • srinirocks
    New Member
    • Sep 2008
    • 4

    Idatareader string values

    I am reading an excel file using ADO.Net. In a column, my first value is nothing and the rest of the values are numbers. But when I read values, I am getting all empty strings. If I replace my first value with some random number, then I am able to read all the values.

    My assumption is that IDataReader is detecting the type by its first value and applying it to rest of the values. Is there a way to tell it to assume everything to be strings? Or any other solution to this problem. (Note: I gottu use DataReader because a lot of the logic in the base classes is based on it and I cannot change it.)

    [CODE]
    while (dreader.Read() )
    {
    if (ProcessRecord( dreader))
    bError = true;
    }


    ProcessRecord(I DataReader dr)
    {
    string value = dr.GetValue(0). ToString();
    }
    [CODE]
  • balabaster
    Recognized Expert Contributor
    • Mar 2007
    • 798

    #2
    I don't know for sure, but I recall that Excel has the same issue when you import files into it. It uses the first few lines to determine the data type and if your data type changes outside those first few lines you're hooped. I can't say for sure that this is the same root cause, but it might be worth investigation to rule it out...

    Comment

    Working...