Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. HELP!!!! DataReader error "No data exists for the row/column"

HELP!!!! DataReader error "No data exists for the row/column"

Scheduled Pinned Locked Moved ASP.NET
helpdatabase
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    bubberz
    wrote on last edited by
    #1

    My code below gives the error "No data exists for the row/column." Sub FindZNumber() 'Declare variable to hold ZNumber entered Dim strZNumber As String = txtZNumber.Text.ToString() 'Start to build select (*) statement to see if a valid ZNumber Dim strSQLZN As String strSQLZN = "SELECT Count(*) As TestCount FROM Table1 WHERE ZNUMBER = '" & strZNumber & "'" Dim dsn As String = ConfigurationSettings.AppSettings("dsn") ODBCConn.Open() Dim cmdZN As New Odbc.OdbcCommand(strSQLZN, ODBCConn) Dim myRDR As Odbc.OdbcDataReader = cmdZN.ExecuteReader() lblTest.Text = myRDR("TestCount") ODBCConn.Close() End Sub I'm trying to populate the label (lblTest) with the count from the SQL String

    S O 2 Replies Last reply
    0
    • B bubberz

      My code below gives the error "No data exists for the row/column." Sub FindZNumber() 'Declare variable to hold ZNumber entered Dim strZNumber As String = txtZNumber.Text.ToString() 'Start to build select (*) statement to see if a valid ZNumber Dim strSQLZN As String strSQLZN = "SELECT Count(*) As TestCount FROM Table1 WHERE ZNUMBER = '" & strZNumber & "'" Dim dsn As String = ConfigurationSettings.AppSettings("dsn") ODBCConn.Open() Dim cmdZN As New Odbc.OdbcCommand(strSQLZN, ODBCConn) Dim myRDR As Odbc.OdbcDataReader = cmdZN.ExecuteReader() lblTest.Text = myRDR("TestCount") ODBCConn.Close() End Sub I'm trying to populate the label (lblTest) with the count from the SQL String

      S Offline
      S Offline
      S Sansanwal
      wrote on last edited by
      #2

      you need to call Read method of reader before accessing any row. The read method points the reader to first row. So, in your code, add myRDR.Read() before lblTest.Text = myRDR("TestCount") Sanjay Sansanwal www.sansanwal.com

      B 1 Reply Last reply
      0
      • B bubberz

        My code below gives the error "No data exists for the row/column." Sub FindZNumber() 'Declare variable to hold ZNumber entered Dim strZNumber As String = txtZNumber.Text.ToString() 'Start to build select (*) statement to see if a valid ZNumber Dim strSQLZN As String strSQLZN = "SELECT Count(*) As TestCount FROM Table1 WHERE ZNUMBER = '" & strZNumber & "'" Dim dsn As String = ConfigurationSettings.AppSettings("dsn") ODBCConn.Open() Dim cmdZN As New Odbc.OdbcCommand(strSQLZN, ODBCConn) Dim myRDR As Odbc.OdbcDataReader = cmdZN.ExecuteReader() lblTest.Text = myRDR("TestCount") ODBCConn.Close() End Sub I'm trying to populate the label (lblTest) with the count from the SQL String

        O Offline
        O Offline
        oykica
        wrote on last edited by
        #3

        If you want to return an aggregate value such as COUNT() use the ExecuteScalar method of the OdbcCommand object. Remember to cast the return value as required. eg. lblTest.Text = CStr(cmdZN.ExecuteScalar())

        B 1 Reply Last reply
        0
        • O oykica

          If you want to return an aggregate value such as COUNT() use the ExecuteScalar method of the OdbcCommand object. Remember to cast the return value as required. eg. lblTest.Text = CStr(cmdZN.ExecuteScalar())

          B Offline
          B Offline
          bubberz
          wrote on last edited by
          #4

          Thanks oykica! I had to put in a Hasrows If then else statement, and got it to work!

          1 Reply Last reply
          0
          • S S Sansanwal

            you need to call Read method of reader before accessing any row. The read method points the reader to first row. So, in your code, add myRDR.Read() before lblTest.Text = myRDR("TestCount") Sanjay Sansanwal www.sansanwal.com

            B Offline
            B Offline
            bubberz
            wrote on last edited by
            #5

            Thanks for the reply Sanjay! I had to look if the datareader HadRows, then that worked.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups