none
SQLDataReader zero results or error RRS feed

  • Question

  • I am trying to determine if a view I am calling using SQLDataReader is returning zero rows or if the view returned an error.  For example, if I have a view that returns 1/0, I should get a divide by zero error.  I see that when I run the view in SSIS.  But I do not know how to check the sqldatareader to see that error.  I just get zero rows returned.

    Does anyone know how to check to see if a view being returned to a sqldatareader has errored out or just did not have any rows returned?

    Thanks,

    LD

    Monday, December 10, 2012 3:54 PM

Answers

All replies

  • Not an expert in this area, but check the following out quickly:

    • What is sqlDataReader.FieldCount for the query in question?

    Valid recordsets should always have a value > 0, even if HasRows == false and no rows were returned.


    "Premature optimization is the root of all evil." - Knuth

    If I provoked thought, please click the green arrow

    If I provoked Aha! please click Propose as Answer

    We are here to learn, to share knowledge, and to earn points; all in about equal measure.


    Monday, December 10, 2012 6:13 PM
  • It returns the column list for the query even with zero rows or and error.
    Monday, December 10, 2012 7:32 PM
  • Hi Ld,

    Welcome to the MSDN Forum.

    Based on my known, when there is a sql error during the sql statement executed, you can get an sqlException in your .net code. 

    http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlexception.errors.aspx 

    It is a collection of sqlError, so you can check the errors for more information, include the error message you mentioned: "a divide by zero error"

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, December 12, 2012 11:00 AM
    Moderator
  • I am going to look at that again, but I was unable to capture the error in earlier attempts.
    Monday, December 17, 2012 1:36 PM
  • Hi Last,

    It is OK. When you find an exactly reproduce way, follow this thread up, please.

    Thanks.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, December 18, 2012 1:58 AM
    Moderator
  • Are you ever calling sqlDataReader.Read() ? It returns false if there are no more rows left, or throws an exception if there are errors.
    Wednesday, December 19, 2012 12:54 AM