Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error: Server Error in '/SIP' Application. No data exists for the row/

Status
Not open for further replies.

technisup

Programmer
Sep 28, 2007
41
US
Hello, I'm trying to retreive info from a query in order to add it to a query but in the process it displays this error:

No data exists for the row/column.
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.InvalidOperationException: No data exists for the row/column.

Source Error:

Line 22: Dim StrReader As OleDbDataReader
Line 23: StrReader = objCmd.ExecuteReader()
Line 24: Response.Write("the value is " + StrReader.Item("clave"))
Line 25: Response.End()
Line 26: 'Dim myCookie As HttpCookie = New HttpCookie("UserSettings")

This is the full code:
Code:
<script runat="server">
    Sub Page_Load(ByVal obj As Object, ByVal e As EventArgs)
        If IsPostBack() Then
            Dim objConn As New OleDbConnection("Provider=SQLNCLI;Server=db2fx981\comware;Database=SIP;Trusted_Connection=yes;")
            objConn.Open()
            Dim sSQL, Resul As String
            sSQL = "select * from usuario where usuario='" & Request("pwdusr") & "' and clave='" & Request("pwdpwd") & "'"
            'Response.Write(sSQL)
            'Response.End()
            '"Insert into Origen (Descripcion) values ('" & Descripcion.Text & "')"
            Dim objCmd As New OleDbCommand(sSQL, objConn)
            
            Resul = objCmd.ExecuteNonQuery
                        
            If Resul Then
                Dim StrReader As OleDbDataReader
                StrReader = objCmd.ExecuteReader()
                Response.Write("el valor es " + StrReader.Item("clave"))
                Response.End()
                'Dim myCookie As HttpCookie = New HttpCookie("UserSettings")
                'myCookie("Font") = "Arial"
                'myCookie("Color") = "Blue"
                'myCookie.Expires = Now.AddDays(1)
                'Response.Cookies.Add(myCookie)
                'Response.Redirect("[URL unfurl="true"]http://www.google.com")[/URL]
                'LblSaved.Visible = True
            Else
                Lblwrong.Visible = True
            End If
        End If
    End Sub

</script>

How can i solve this?

Thx.
 
you need to iterator the reader, or get a reference to the first row.
Code:
dim rowindex as integer = 0
sttreader(rowindex)("clave")
or however vb does it.

there are a couple problems beyond this though.
1. you are not seperating the code from the markup. this one of the key benefits to webforms. 1 file for markup, another for code (not the problem though, just another fyi).

2. your using 1 command object to read and write data. you should only have 1 sql statement per command object. this simplifies design and bug location.

3. since clave is part of the request, why query the database for the value? just use request("clave").

4. you are not properly closing/disposing the command or connection. this will lead to problems when an error occurs. use a using block to manage the connection/command. for more
info on these topics search these forums or google. they are common problems. (this isn't the current problem but can easily become one in the future.)

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top