No data exists for the row/column

hi

i am getitng the above error on executing hte below code:
Private Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
        Dim txtString As String = Me.txtServerNameUp.Text.ToUpper
        If Not TypeOf txtString Is System.DBNull Then
            strSQL = "select [IDKey] from ServerMain where [name] ='" & txtString & "'"
        End If
        Dim connString As String = ConfigurationSettings.AppSettings("ConnectionString")
        Dim objConnection As OleDbConnection = New OleDbConnection(connString)
        Dim objCommand As OleDbCommand = New OleDbCommand(strSQL, objConnection)
        Dim objDataReader As OleDbDataReader = Nothing
        Dim loginCheck As Boolean = False
        objConnection.Open()
        objDataReader = objCommand.ExecuteReader()

        While objDataReader.Read
            loginCheck = True
        End While
        If loginCheck = True Then
            'idRecd = objDataReader("IDKey")
            objDataReader.Close()
            Response.Write(objDataReader("IDKey"))
            funcRetData()

        End If
    End Sub

the error is comign at Response.Write(objDataReader("IDKey")), i am usin gaccess db
can anyone suggest me whats the reason for this

thanks
LVL 1
samir25Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ArjiCommented:
It appears you are closing the objDataReader object and then trying to read from it:

Response.Write(objDataReader("IDKey"))
objDataReader.Close()
funcRetData()

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
thenelsonCommented:
Also you can't assign the value in a dim statement:
Dim txtString As String = Me.txtServerNameUp.Text.ToUpper
should be:
Dim txtString As String
txtString  = Me.txtServerNameUp.Text.ToUpper
I'm surprised you didn't get a compile error.

I am not familiar with the syntex of the write statement:
Response.Write(objDataReader("IDKey"))
I've always used:
objDataReader.Write("IDKey")
but objDataReader was closed the line before.
flavoCommented:
Hi thenelson,
> Dim txtString As String = Me.txtServerNameUp.Text.ToUpper

From the looks of things this is VB .Net (ASP) and this is completely valid syntax.

Idea???

Dave
Your Guide to Achieving IT Business Success

The IT Service Excellence Tool Kit has best practices to keep your clients happy and business booming. Inside, you’ll find everything you need to increase client satisfaction and retention, become more competitive, and increase your overall success.

samir25Author Commented:
i tried thi salso
Private Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
        Dim txtString As String
        txtString = Me.txtServerNameUp.Text.ToUpper
        If Not TypeOf txtString Is System.DBNull Then
            strSQL = "select [IDKey] from ServerMain where [name] ='" & txtString & "'"
        End If
        Dim connString As String = ConfigurationSettings.AppSettings("ConnectionString")
        Dim objConnection As OleDbConnection = New OleDbConnection(connString)
        Dim objCommand As OleDbCommand = New OleDbCommand(strSQL, objConnection)
        Dim objDataReader As OleDbDataReader = Nothing
        Dim loginCheck As Boolean = False
        objConnection.Open()
        objDataReader = objCommand.ExecuteReader()

        While objDataReader.Read
            loginCheck = True
        End While
        If loginCheck = True Then
            idRecd = objDataReader("IDKey")
            objDataReader.Close()
            'Response.Write(objDataReader("IDKey"))
            funcRetData()

        End If
    End Sub
i stil get hte error
idrecd is an integer
samir25Author Commented:
i tried thi s also
Private Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
        Dim txtString As String
        txtString = Me.txtServerNameUp.Text.ToUpper
        If Not TypeOf txtString Is System.DBNull Then
            strSQL = "select [IDKey] from ServerMain where [name] ='" & txtString & "'"
        End If
        Dim connString As String = ConfigurationSettings.AppSettings("ConnectionString")
        Dim objConnection As OleDbConnection = New OleDbConnection(connString)
        objConnection.Open()
        Dim objCommand As OleDbCommand = New OleDbCommand(strSQL, objConnection)
        Dim objDataReader As OleDbDataReader = Nothing
        Dim loginCheck As Boolean = False

        objDataReader = objCommand.ExecuteScalar

        While objDataReader.Read
            loginCheck = True
        End While
        Dim str1 As String

        If loginCheck = True Then
            str1 = objDataReader("IDKey")
            objDataReader.Close()
            'Response.Write(objDataReader("IDKey"))
            funcRetData()

        End If
    End Sub
for which i get this error at line 519

Specified cast is not valid.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidCastException: Specified cast is not valid.

Source Error:


Line 517:        Dim loginCheck As Boolean = False
Line 518:
Line 519:        objDataReader = objCommand.ExecuteScalar
Line 520:
Line 521:        While objDataReader.Read
 
samir25Author Commented:
i figured this out...it was coming because the reader pointer was going to the next record which was empty so i trap the value while i read the 1st record itsef

While objDataReader.Read
            loginCheck = True
            idRecd = objDataReader("IDKey")
        End While
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.