Problems to use my recordset

E

egsdar

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

ResponsablePropuesta.Observaciones
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.IndexOutOfRangeException:
ResponsablePropuesta.Observaciones

Source Error:


Line 26: 'txtMargen.Text = RSq("ResponsablePropuesta.Margen")
Line 27: 'txtOBS.Text =
Line 28: Response.Write(RSq("ResponsablePropuesta.Observaciones"))
Line 29:
Line 30: End If


Source File: C:\Documents and Settings\Edgar Salcedo\Mis documentos\Visual
Studio 2005\WebSites\SIP\LineasMod.aspx.vb Line: 28

Stack Trace:


[IndexOutOfRangeException: ResponsablePropuesta.Observaciones]
System.Data.ProviderBase.FieldNameLookup.GetOrdinal(String fieldName) +95
System.Data.SqlClient.SqlDataReader.GetOrdinal(String name) +168
System.Data.SqlClient.SqlDataReader.get_Item(String name) +35
LineasMod.Page_Load(Object sender, EventArgs e) in C:\Documents and
Settings\Edgar Salcedo\Mis documentos\Visual Studio
2005\WebSites\SIP\LineasMod.aspx.vb:28
System.Web.UI.Control.OnLoad(EventArgs e) +88
System.Web.UI.Control.LoadRecursive() +74
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3021


And this is my code:

If Not IsPostBack() Then
HiddenField1.Value = Request("id")
cmbRG.SelectedValue = Request("rg")
cmbRP.SelectedValue = Request("rp")
Dim sqlr As String = "SELECT ResponsablePropuesta.Idpropuesta AS
Id, Prospecto.Nombre AS Prospecto, Usuario.IdUsuario AS IdRG, Usuario.Nombre
AS RespGrupo, Usuario_1.IdUsuario AS IdRP, Usuario_1.Nombre AS RespProp,
ResponsablePropuesta.FechaPlanEntrega,
ResponsablePropuesta.ValorPropuestaCOP,
ResponsablePropuesta.ValorPropuestaUSD, ResponsablePropuesta.Margen,
ResponsablePropuesta.Observaciones FROM ResponsablePropuesta INNER JOIN
Propuesta ON ResponsablePropuesta.Idpropuesta = Propuesta.IdPropuesta INNER
JOIN Prospecto ON Propuesta.IdProspecto = Prospecto.IdProspecto INNER JOIN
Usuario ON ResponsablePropuesta.RespGrupo = Usuario.IdUsuario INNER JOIN
Usuario AS Usuario_1 ON ResponsablePropuesta.RespPropuesta =
Usuario_1.IdUsuario WHERE (ResponsablePropuesta.Idpropuesta = " &
Request("id") & ") AND (Usuario.IdUsuario = " & Request("rg") & ") AND
(Usuario_1.IdUsuario = " & Request("rp") & ")"
Dim sqlConn As System.Data.SqlClient.SqlConnection
Dim sqlCmd As System.Data.SqlClient.SqlCommand
Dim strConnection As String
Dim RSq As System.Data.SqlClient.SqlDataReader
strConnection =
ConfigurationManager.ConnectionStrings("SIPconnectionstring").ConnectionString
'System.Configuration.ConfigurationManager.AppSettings("Prueba3")
sqlConn = New System.Data.SqlClient.SqlConnection(strConnection)
sqlCmd = New System.Data.SqlClient.SqlCommand(sqlr, sqlConn)
sqlConn.Open()

RSq = sqlCmd.ExecuteReader()
RSq.Read()
'txtFechaPlan.text = RSq("ResponsablePropuesta.FechaPlanEntrega")
'TxtCOP.Text = RSq("ResponsablePropuesta.ValorPropuestaCOP")
'TxtUSD.Text = RSq("ResponsablePropuesta.ValorPropuestaUSD")
'txtMargen.Text = RSq("ResponsablePropuesta.Margen")
'txtOBS.Text =
Response.Write(RSq("ResponsablePropuesta.Observaciones"))

End If

How can I solve this?

Thx
 
G

Gregory A. Beamer

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.


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

ResponsablePropuesta.Observaciones
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.IndexOutOfRangeException:
ResponsablePropuesta.Observaciones

Source Error:


Line 26: 'txtMargen.Text = RSq("ResponsablePropuesta.Margen")
Line 27: 'txtOBS.Text =
Line 28:
Response.Write(RSq("ResponsablePropuesta.Observaciones"))
Line 29:
Line 30: End If


Source File: C:\Documents and Settings\Edgar Salcedo\Mis documentos\Visual
Studio 2005\WebSites\SIP\LineasMod.aspx.vb Line: 28

Stack Trace:


[IndexOutOfRangeException: ResponsablePropuesta.Observaciones]
System.Data.ProviderBase.FieldNameLookup.GetOrdinal(String fieldName)
+95
System.Data.SqlClient.SqlDataReader.GetOrdinal(String name) +168
System.Data.SqlClient.SqlDataReader.get_Item(String name) +35
LineasMod.Page_Load(Object sender, EventArgs e) in C:\Documents and
Settings\Edgar Salcedo\Mis documentos\Visual Studio
2005\WebSites\SIP\LineasMod.aspx.vb:28
System.Web.UI.Control.OnLoad(EventArgs e) +88
System.Web.UI.Control.LoadRecursive() +74
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3021


And this is my code:

If Not IsPostBack() Then
HiddenField1.Value = Request("id")
cmbRG.SelectedValue = Request("rg")
cmbRP.SelectedValue = Request("rp")
Dim sqlr As String = "SELECT ResponsablePropuesta.Idpropuesta
AS
Id, Prospecto.Nombre AS Prospecto, Usuario.IdUsuario AS IdRG,
Usuario.Nombre
AS RespGrupo, Usuario_1.IdUsuario AS IdRP, Usuario_1.Nombre AS RespProp,
ResponsablePropuesta.FechaPlanEntrega,
ResponsablePropuesta.ValorPropuestaCOP,
ResponsablePropuesta.ValorPropuestaUSD, ResponsablePropuesta.Margen,
ResponsablePropuesta.Observaciones FROM ResponsablePropuesta INNER JOIN
Propuesta ON ResponsablePropuesta.Idpropuesta = Propuesta.IdPropuesta
INNER
JOIN Prospecto ON Propuesta.IdProspecto = Prospecto.IdProspecto INNER JOIN
Usuario ON ResponsablePropuesta.RespGrupo = Usuario.IdUsuario INNER JOIN
Usuario AS Usuario_1 ON ResponsablePropuesta.RespPropuesta =
Usuario_1.IdUsuario WHERE (ResponsablePropuesta.Idpropuesta = " &
Request("id") & ") AND (Usuario.IdUsuario = " & Request("rg") & ") AND
(Usuario_1.IdUsuario = " & Request("rp") & ")"
Dim sqlConn As System.Data.SqlClient.SqlConnection
Dim sqlCmd As System.Data.SqlClient.SqlCommand
Dim strConnection As String
Dim RSq As System.Data.SqlClient.SqlDataReader
strConnection =
ConfigurationManager.ConnectionStrings("SIPconnectionstring").ConnectionString

'System.Configuration.ConfigurationManager.AppSettings("Prueba3")
sqlConn = New
System.Data.SqlClient.SqlConnection(strConnection)
sqlCmd = New System.Data.SqlClient.SqlCommand(sqlr, sqlConn)
sqlConn.Open()

RSq = sqlCmd.ExecuteReader()
RSq.Read()
'txtFechaPlan.text =
RSq("ResponsablePropuesta.FechaPlanEntrega")
'TxtCOP.Text = RSq("ResponsablePropuesta.ValorPropuestaCOP")
'TxtUSD.Text = RSq("ResponsablePropuesta.ValorPropuestaUSD")
'txtMargen.Text = RSq("ResponsablePropuesta.Margen")
'txtOBS.Text =
Response.Write(RSq("ResponsablePropuesta.Observaciones"))

End If

How can I solve this?

Thx
 
E

egsdar

Mark Rae said:
Do you mean rsq.HasRows()? If so, where do you use that? HasRows() doesn't
appear anywhere in the code you posted...

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,479
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top