none
Getting Exception in SQL SERVER 2005 RRS feed

  • Question

  • Hi!

    I am developing an application with "Visual Studio 2008" (in language VB.NET, Framework: 3.5) with data server as "SQL SERVER EXPRESS 2005".

    i have one table with name [fyr] and it contains two columns 'fyid' (integer) and 'fyear' (nvarchar(50)).

    following queries are showing exception as "No data exists for row/column"

    Dim cmd As New OleDbCommand("SELECT * FROM fyr WHERE fyear= '" & DateTime.Now.ToString("yy") & "-" & DateTime.Now.ToString("yy") + 1 & "'", Connection.Instance)

    Dim cmd As New OleDbCommand("select * from fyr where fyear = '12-13'", Connection.Instance)

    Dim bdr As OleDbDataReader = cmd.ExecuteReader()

    both queries above has same result.

    but all these queries are working if executed directly in "SQL SERVER Management Studio" and showing the expected results.

    and connection is in open state all other queries in the project are executing correctly and successfully.

    The table has the data like this:

    fyid fyear

    1 11-12

    7 12-13

    Please help me.

    • Moved by 许阳(无锡) Monday, April 23, 2012 8:40 AM Data Issue (From:Visual Studio Tools for Office)
    Sunday, April 22, 2012 6:22 AM

Answers

  • Hi SAGAR_DJ,

    Welcome to MSDN Forum.

    After ExecuteReader is called, the bdr is positioned before the first returned record, you need to use Read() method to read records. If the result is multiple, the code should be writen as below,

    While(bdr.Read())
    {
        ...
    }

    Best Regards

    Allen Li [MSFT]
    MSDN Community Support | Feedback to us

    Tuesday, April 24, 2012 5:33 AM
    Moderator

All replies