Problems to use my recordset

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?ZWdzZGFy?=

    #1

    Problems to use my recordset

    I'm having issues to use my recordset, this is the error I'm getting:

    ResponsableProp uesta.Observaci ones
    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.IndexOut OfRangeExceptio n:
    ResponsableProp uesta.Observaci ones

    Source Error:


    Line 26: 'txtMargen.Text = RSq("Responsabl ePropuesta.Marg en")
    Line 27: 'txtOBS.Text =
    Line 28: Response.Write( RSq("Responsabl ePropuesta.Obse rvaciones"))
    Line 29:
    Line 30: End If


    Source File: C:\Documents and Settings\Edgar Salcedo\Mis documentos\Visu al
    Studio 2005\WebSites\S IP\LineasMod.as px.vb Line: 28

    Stack Trace:


    [IndexOutOfRange Exception: ResponsableProp uesta.Observaci ones]
    System.Data.Pro viderBase.Field NameLookup.GetO rdinal(String fieldName) +95
    System.Data.Sql Client.SqlDataR eader.GetOrdina l(String name) +168
    System.Data.Sql Client.SqlDataR eader.get_Item( String name) +35
    LineasMod.Page_ Load(Object sender, EventArgs e) in C:\Documents and
    Settings\Edgar Salcedo\Mis documentos\Visu al Studio
    2005\WebSites\S IP\LineasMod.as px.vb:28
    System.Web.UI.C ontrol.OnLoad(E ventArgs e) +88
    System.Web.UI.C ontrol.LoadRecu rsive() +74
    System.Web.UI.P age.ProcessRequ estMain(Boolean
    includeStagesBe foreAsyncPoint, Boolean includeStagesAf terAsyncPoint) +3021


    And this is my code:

    If Not IsPostBack() Then
    HiddenField1.Va lue = Request("id")
    cmbRG.SelectedV alue = Request("rg")
    cmbRP.SelectedV alue = Request("rp")
    Dim sqlr As String = "SELECT ResponsableProp uesta.Idpropues ta AS
    Id, Prospecto.Nombr e AS Prospecto, Usuario.IdUsuar io AS IdRG, Usuario.Nombre
    AS RespGrupo, Usuario_1.IdUsu ario AS IdRP, Usuario_1.Nombr e AS RespProp,
    ResponsableProp uesta.FechaPlan Entrega,
    ResponsableProp uesta.ValorProp uestaCOP,
    ResponsableProp uesta.ValorProp uestaUSD, ResponsableProp uesta.Margen,
    ResponsableProp uesta.Observaci ones FROM ResponsableProp uesta INNER JOIN
    Propuesta ON ResponsableProp uesta.Idpropues ta = Propuesta.IdPro puesta INNER
    JOIN Prospecto ON Propuesta.IdPro specto = Prospecto.IdPro specto INNER JOIN
    Usuario ON ResponsableProp uesta.RespGrupo = Usuario.IdUsuar io INNER JOIN
    Usuario AS Usuario_1 ON ResponsableProp uesta.RespPropu esta =
    Usuario_1.IdUsu ario WHERE (ResponsablePro puesta.Idpropue sta = " &
    Request("id") & ") AND (Usuario.IdUsua rio = " & Request("rg") & ") AND
    (Usuario_1.IdUs uario = " & Request("rp") & ")"
    Dim sqlConn As System.Data.Sql Client.SqlConne ction
    Dim sqlCmd As System.Data.Sql Client.SqlComma nd
    Dim strConnection As String
    Dim RSq As System.Data.Sql Client.SqlDataR eader
    strConnection =
    ConfigurationMa nager.Connectio nStrings("SIPco nnectionstring" ).ConnectionStr ing
    'System.Configu ration.Configur ationManager.Ap pSettings("Prue ba3")
    sqlConn = New System.Data.Sql Client.SqlConne ction(strConnec tion)
    sqlCmd = New System.Data.Sql Client.SqlComma nd(sqlr, sqlConn)
    sqlConn.Open()

    RSq = sqlCmd.ExecuteR eader()
    RSq.Read()
    'txtFechaPlan.t ext = RSq("Responsabl ePropuesta.Fech aPlanEntrega")
    'TxtCOP.Text = RSq("Responsabl ePropuesta.Valo rPropuestaCOP")
    'TxtUSD.Text = RSq("Responsabl ePropuesta.Valo rPropuestaUSD")
    'txtMargen.Text = RSq("Responsabl ePropuesta.Marg en")
    'txtOBS.Text =
    Response.Write( RSq("Responsabl ePropuesta.Obse rvaciones"))

    End If

    How can I solve this?

    Thx

  • Gregory A. Beamer

    #2
    Re: Problems to use my recordset

    Index out of range means it is asking for a record that does not exist. If I
    were guessing, which I am, I would guess the reader found no records. To
    avoid this, either make sure there is a record or use a while() and pull all
    records off the reader.

    Another option is to use a DataSet and confirm there are rows.

    --
    Gregory A. Beamer
    MVP: MCP: +I, SE, SD, DBA

    Blog:


    *************** *************** **************
    | Think Outside the Box! |
    *************** *************** **************
    "egsdar" <egsdar@discuss ions.microsoft. comwrote in message
    news:9B6788E0-6665-4339-90C2-4235D321FAC8@mi crosoft.com...
    I'm having issues to use my recordset, this is the error I'm getting:
    >
    ResponsableProp uesta.Observaci ones
    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.IndexOut OfRangeExceptio n:
    ResponsableProp uesta.Observaci ones
    >
    Source Error:
    >
    >
    Line 26: 'txtMargen.Text = RSq("Responsabl ePropuesta.Marg en")
    Line 27: 'txtOBS.Text =
    Line 28:
    Response.Write( RSq("Responsabl ePropuesta.Obse rvaciones"))
    Line 29:
    Line 30: End If
    >
    >
    Source File: C:\Documents and Settings\Edgar Salcedo\Mis documentos\Visu al
    Studio 2005\WebSites\S IP\LineasMod.as px.vb Line: 28
    >
    Stack Trace:
    >
    >
    [IndexOutOfRange Exception: ResponsableProp uesta.Observaci ones]
    System.Data.Pro viderBase.Field NameLookup.GetO rdinal(String fieldName)
    +95
    System.Data.Sql Client.SqlDataR eader.GetOrdina l(String name) +168
    System.Data.Sql Client.SqlDataR eader.get_Item( String name) +35
    LineasMod.Page_ Load(Object sender, EventArgs e) in C:\Documents and
    Settings\Edgar Salcedo\Mis documentos\Visu al Studio
    2005\WebSites\S IP\LineasMod.as px.vb:28
    System.Web.UI.C ontrol.OnLoad(E ventArgs e) +88
    System.Web.UI.C ontrol.LoadRecu rsive() +74
    System.Web.UI.P age.ProcessRequ estMain(Boolean
    includeStagesBe foreAsyncPoint, Boolean includeStagesAf terAsyncPoint) +3021
    >
    >
    And this is my code:
    >
    If Not IsPostBack() Then
    HiddenField1.Va lue = Request("id")
    cmbRG.SelectedV alue = Request("rg")
    cmbRP.SelectedV alue = Request("rp")
    Dim sqlr As String = "SELECT ResponsableProp uesta.Idpropues ta
    AS
    Id, Prospecto.Nombr e AS Prospecto, Usuario.IdUsuar io AS IdRG,
    Usuario.Nombre
    AS RespGrupo, Usuario_1.IdUsu ario AS IdRP, Usuario_1.Nombr e AS RespProp,
    ResponsableProp uesta.FechaPlan Entrega,
    ResponsableProp uesta.ValorProp uestaCOP,
    ResponsableProp uesta.ValorProp uestaUSD, ResponsableProp uesta.Margen,
    ResponsableProp uesta.Observaci ones FROM ResponsableProp uesta INNER JOIN
    Propuesta ON ResponsableProp uesta.Idpropues ta = Propuesta.IdPro puesta
    INNER
    JOIN Prospecto ON Propuesta.IdPro specto = Prospecto.IdPro specto INNER JOIN
    Usuario ON ResponsableProp uesta.RespGrupo = Usuario.IdUsuar io INNER JOIN
    Usuario AS Usuario_1 ON ResponsableProp uesta.RespPropu esta =
    Usuario_1.IdUsu ario WHERE (ResponsablePro puesta.Idpropue sta = " &
    Request("id") & ") AND (Usuario.IdUsua rio = " & Request("rg") & ") AND
    (Usuario_1.IdUs uario = " & Request("rp") & ")"
    Dim sqlConn As System.Data.Sql Client.SqlConne ction
    Dim sqlCmd As System.Data.Sql Client.SqlComma nd
    Dim strConnection As String
    Dim RSq As System.Data.Sql Client.SqlDataR eader
    strConnection =
    ConfigurationMa nager.Connectio nStrings("SIPco nnectionstring" ).ConnectionStr ing
    >
    'System.Configu ration.Configur ationManager.Ap pSettings("Prue ba3")
    sqlConn = New
    System.Data.Sql Client.SqlConne ction(strConnec tion)
    sqlCmd = New System.Data.Sql Client.SqlComma nd(sqlr, sqlConn)
    sqlConn.Open()
    >
    RSq = sqlCmd.ExecuteR eader()
    RSq.Read()
    'txtFechaPlan.t ext =
    RSq("Responsabl ePropuesta.Fech aPlanEntrega")
    'TxtCOP.Text = RSq("Responsabl ePropuesta.Valo rPropuestaCOP")
    'TxtUSD.Text = RSq("Responsabl ePropuesta.Valo rPropuestaUSD")
    'txtMargen.Text = RSq("Responsabl ePropuesta.Marg en")
    'txtOBS.Text =
    Response.Write( RSq("Responsabl ePropuesta.Obse rvaciones"))
    >
    End If
    >
    How can I solve this?
    >
    Thx
    >

    Comment

    • Mark Rae [MVP]

      #3
      Re: Problems to use my recordset

      "Gregory A. Beamer" <NoSpamMgbworld @comcast.netNoS pamMwrote in message
      news:us06HnyRJH A.6052@TK2MSFTN GP02.phx.gbl...
      >How can I solve this?
      >
      Index out of range means it is asking for a record that does not exist. If
      I were guessing, which I am, I would guess the reader found no records. To
      avoid this, either make sure there is a record or use a while() and pull
      all records off the reader.
      >
      Another option is to use a DataSet and confirm there are rows.
      Or stick with a DataReader and confirm that there are rows:
      http://msdn.microsoft.com/en-us/libr...r.hasrows.aspx


      --
      Mark Rae
      ASP.NET MVP


      Comment

      • =?Utf-8?B?ZWdzZGFy?=

        #4
        Re: Problems to use my recordset

        "Mark Rae [MVP]" wrote:
        "Gregory A. Beamer" <NoSpamMgbworld @comcast.netNoS pamMwrote in message
        news:us06HnyRJH A.6052@TK2MSFTN GP02.phx.gbl...
        >
        How can I solve this?
        Index out of range means it is asking for a record that does not exist. If
        I were guessing, which I am, I would guess the reader found no records. To
        avoid this, either make sure there is a record or use a while() and pull
        all records off the reader.

        Another option is to use a DataSet and confirm there are rows.
        >
        Or stick with a DataReader and confirm that there are rows:
        http://msdn.microsoft.com/en-us/libr...r.hasrows.aspx
        >
        >
        --
        Mark Rae
        ASP.NET MVP

        >
        >
        Thanks for your post.
        I used rsq.hasrow and actually it has rows, so how can i fix this?

        Comment

        • Mark Rae [MVP]

          #5
          Re: Problems to use my recordset

          "egsdar" <egsdar@discuss ions.microsoft. comwrote in message
          news:BD86498E-BD0A-4D3A-9B68-0FA3AE41FC4B@mi crosoft.com...
          >Or stick with a DataReader and confirm that there are rows:
          >http://msdn.microsoft.com/en-us/libr...r.hasrows.aspx
          >
          I used rsq.hasrow and actually it has rows, so how can i fix this?
          Do you mean rsq.HasRows()? If so, where do you use that? HasRows() doesn't
          appear anywhere in the code you posted...


          --
          Mark Rae
          ASP.NET MVP


          Comment

          • =?Utf-8?B?ZWdzZGFy?=

            #6
            Re: Problems to use my recordset


            "Mark Rae [MVP]" wrote:
            "egsdar" <egsdar@discuss ions.microsoft. comwrote in message
            news:BD86498E-BD0A-4D3A-9B68-0FA3AE41FC4B@mi crosoft.com...
            >
            Or stick with a DataReader and confirm that there are rows:
            http://msdn.microsoft.com/en-us/libr...r.hasrows.aspx
            I used rsq.hasrow and actually it has rows, so how can i fix this?
            >
            Do you mean rsq.HasRows()? If so, where do you use that? HasRows() doesn't
            appear anywhere in the code you posted...
            >
            >
            --
            Mark Rae
            ASP.NET MVP

            >
            >
            Well, I did it as part of your suggention just to check.

            If rsq.hasrows() then
            response.write( "With rows")
            else
            response.write( "Without rows")
            end if

            Comment

            • Mark Rae [MVP]

              #7
              Re: Problems to use my recordset

              "egsdar" <egsdar@discuss ions.microsoft. comwrote in message
              news:7E4DA952-10FA-4A93-8BD2-EC66C73D82E6@mi crosoft.com...
              Well, I did it as part of your suggention just to check.
              >
              If rsq.hasrows() then
              response.write( "With rows")
              else
              response.write( "Without rows")
              end if

              Can you try this, please:

              sqlConn.Open()
              RSq = sqlCmd.ExecuteR eader()
              If Rsq.HasRows() Then
              RSq.Read()
              Response.Write( RSq("Observacio nes").ToString( ))
              End If


              --
              Mark Rae
              ASP.NET MVP


              Comment

              Working...