I am interrupted in my code. Whilst using OLEdbReader object.
I would like to skip the last row of reader object ,which contains non-acceptable string .At time of reading object it shows "HasRows" true..while read by read operation gives me null.
i,ve tried string.IsnullorEmpty().no success.
Help is really appreciated.
Regards
Sachin Kalia


Sachin KaliaRank #102 · 20.8K reputationPosted Jul 16, 2012, 5:20 AM EDT
There is no update on this article since few days.
Can anyone have a look and advise me to come out from this issue.
Hihgly Thankful.
VulpesRank #55 · 29.2K reputationPosted Jul 16, 2012, 5:44 AM EDT
For example, if it's the column with an index of 'n' that you're trying to read:
if (!reader.IsDBNull(n))
{
// read the actual value
}
Sachin KaliaRank #102 · 20.8K reputationPosted Jul 16, 2012, 7:56 PM EDT
Thanks for your initiate.
I've already tried this.this function use to check the Column value existence.
I want to skip the complete row from any excel sheet or csv file.
Kind of we do have skip function in LINQ.
I'm using C# 3.0.
Thanks
Chees DotNet :)
Jignesh TrivediRank #16 · 50.3K reputationPosted Jul 16, 2012, 7:59 PM EDT
You may use the "as" operator combined with the "??" operator for default values. Value types will need to be read as nullable and given a default.
string test1 = sqlreader[index] as string; // for string value.
int myInt = sqlreader[index] as int? ?? default(int); // for int value.
hope this will help you.
VulpesRank #55 · 29.2K reputationPosted Jul 17, 2012, 1:53 AM EDT
So, unless you know in advance how many records are going to be returned, there's no way to skip reading the last row entirely.
Sachin KaliaRank #102 · 20.8K reputationPosted Jul 17, 2012, 2:13 AM EDT
This is the problem with the OleDbDataReader is that you don't know how many rows there are to be read until it's read the last one.
Whislt i've found a workaround for this and would like to share with you all .
@ time of reading CSV used this code,yes it may be bit odd but satiesfied my requirement