Click here to Skip to main content
15,902,635 members
Home / Discussions / C#
   

C#

 
AnswerRe: open an av file Pin
Bassam Saoud8-Jan-10 12:34
Bassam Saoud8-Jan-10 12:34 
AnswerRe: open an av file Pin
Ravi Bhavnani8-Jan-10 13:41
professionalRavi Bhavnani8-Jan-10 13:41 
AnswerRe: open an avi file Pin
ajith-k-rajagopalan8-Jan-10 21:52
ajith-k-rajagopalan8-Jan-10 21:52 
QuestionSqlDataReader reading beyond end of data Pin
TheJudeDude8-Jan-10 11:58
TheJudeDude8-Jan-10 11:58 
AnswerRe: SqlDataReader reading beyond end of data Pin
Bassam Saoud8-Jan-10 12:31
Bassam Saoud8-Jan-10 12:31 
AnswerRe: SqlDataReader reading beyond end of data Pin
Jimmanuel8-Jan-10 12:33
Jimmanuel8-Jan-10 12:33 
GeneralRe: SqlDataReader reading beyond end of data Pin
TheJudeDude11-Jan-10 5:16
TheJudeDude11-Jan-10 5:16 
GeneralRe: SqlDataReader reading beyond end of data Pin
Jimmanuel11-Jan-10 6:39
Jimmanuel11-Jan-10 6:39 
What if the data is NULL in the database? Before you check sqlReader["SOME FIELD"] against your target value you should check it against DBNull.Value.

Also, this:
sqlReader.Read()//advance to next record
if (!sqlReader.HasRows)//there's no more data

has the same problem as before. HasRows doesn't care if you called Read or how many times it's called. It always returns the same thing. You shouldn't have more than one call to Read and you should always check it's return value.

What it looks like you're trying to do if go through all of the rows in the reader and do some work when the value of sqlReader["SOME FIELD"] equals variable. If you found variable then exit the loop.

If that's what you're doing then try this:
bool found = false;

while (sqlReader.Read() && !found)
{
    if (sqlReader["SOME FIELD"] == DBNull.Value)
    {
        // advance to the next row
        continue;
    }

    // convert the data to the appropriate type here, I'm using string as an example
    string dbVal = sqlReader["SOME FIELD"] as string;

    if (dbVal != variable)
    {
        // advance to the next row
        continue;
    }

    // value is found!
    found = true;
    // do something . . . 
}

Even if it's not what you're doing, note that there's only one Read, it's return value is checked and we're checking for DBNull.Value. dbValshould be the same type as whatever variable is, I just picked string as an example. Also note that <code>HasRows is not needed.

Badger | [badger,badger,badger,badger...]

GeneralRe: SqlDataReader reading beyond end of data Pin
TheJudeDude11-Jan-10 9:04
TheJudeDude11-Jan-10 9:04 
GeneralRe: SqlDataReader reading beyond end of data Pin
Jimmanuel11-Jan-10 9:49
Jimmanuel11-Jan-10 9:49 
AnswerRe: SqlDataReader reading beyond end of data Pin
Migounette8-Jan-10 12:34
Migounette8-Jan-10 12:34 
AnswerRe: SqlDataReader reading beyond end of data Pin
ajith-k-rajagopalan8-Jan-10 21:56
ajith-k-rajagopalan8-Jan-10 21:56 
GeneralRe: SqlDataReader reading beyond end of data Pin
TheJudeDude11-Jan-10 5:27
TheJudeDude11-Jan-10 5:27 
QuestionHelp on converting to XML Pin
amadaeliseo8-Jan-10 8:59
amadaeliseo8-Jan-10 8:59 
AnswerRe: Help on converting to XML Pin
Dimitri Witkowski8-Jan-10 22:08
Dimitri Witkowski8-Jan-10 22:08 
QuestionFeature from Java... is in C#? [modified] Pin
ika28-Jan-10 8:34
ika28-Jan-10 8:34 
AnswerRe: Feature from Java... is in C#? Pin
harold aptroot8-Jan-10 9:09
harold aptroot8-Jan-10 9:09 
AnswerRe: Feature from Java... is in C#? Pin
Nicholas Butler8-Jan-10 9:12
sitebuilderNicholas Butler8-Jan-10 9:12 
GeneralRe: Feature from Java... is in C#? Pin
ika28-Jan-10 11:16
ika28-Jan-10 11:16 
AnswerRe: Feature from Java... is in C#? Pin
Pete O'Hanlon8-Jan-10 11:20
mvePete O'Hanlon8-Jan-10 11:20 
AnswerRe: Feature from Java... is in C#? Pin
N a v a n e e t h8-Jan-10 19:17
N a v a n e e t h8-Jan-10 19:17 
Questiongeneral help Pin
hotthoughtguy8-Jan-10 8:15
hotthoughtguy8-Jan-10 8:15 
AnswerRe: general help Pin
#realJSOP8-Jan-10 8:25
professional#realJSOP8-Jan-10 8:25 
GeneralRe: general help Pin
hotthoughtguy8-Jan-10 8:31
hotthoughtguy8-Jan-10 8:31 
AnswerRe: general help Pin
Bassam Saoud8-Jan-10 12:37
Bassam Saoud8-Jan-10 12:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.