By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,078 Members | 1,846 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,078 IT Pros & Developers. It's quick & easy.

Problems to use my recordset

P: n/a
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.Observaci ones"))
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.GetOrdina l(String fieldName) +95
System.Data.SqlClient.SqlDataReader.GetOrdinal(Str ing name) +168
System.Data.SqlClient.SqlDataReader.get_Item(Strin g 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("SIPconnect ionstring").ConnectionString
'System.Configuration.ConfigurationManager.AppSett ings("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.Observaci ones"))

End If

How can I solve this?

Thx

Nov 15 '08 #1
Share this Question
Share on Google+
6 Replies


P: n/a
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:
http://feeds.feedburner.com/GregoryBeamer

********************************************
| Think Outside the Box! |
********************************************
"egsdar" <eg****@discussions.microsoft.comwrote in message
news:9B**********************************@microsof t.com...
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.Observaci ones"))
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.GetOrdina l(String fieldName)
+95
System.Data.SqlClient.SqlDataReader.GetOrdinal(Str ing name) +168
System.Data.SqlClient.SqlDataReader.get_Item(Strin g 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("SIPconnect ionstring").ConnectionString

'System.Configuration.ConfigurationManager.AppSett ings("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.Observaci ones"))

End If

How can I solve this?

Thx
Nov 15 '08 #2

P: n/a
"Gregory A. Beamer" <No************@comcast.netNoSpamMwrote in message
news:us**************@TK2MSFTNGP02.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
http://www.markrae.net

Nov 15 '08 #3

P: n/a
"Mark Rae [MVP]" wrote:
"Gregory A. Beamer" <No************@comcast.netNoSpamMwrote in message
news:us**************@TK2MSFTNGP02.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
http://www.markrae.net

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

Nov 16 '08 #4

P: n/a
"egsdar" <eg****@discussions.microsoft.comwrote in message
news:BD**********************************@microsof t.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
http://www.markrae.net

Nov 16 '08 #5

P: n/a

"Mark Rae [MVP]" wrote:
"egsdar" <eg****@discussions.microsoft.comwrote in message
news:BD**********************************@microsof t.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
http://www.markrae.net

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
Nov 16 '08 #6

P: n/a
"egsdar" <eg****@discussions.microsoft.comwrote in message
news:7E**********************************@microsof t.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.ExecuteReader()
If Rsq.HasRows() Then
RSq.Read()
Response.Write(RSq("Observaciones").ToString())
End If
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Nov 16 '08 #7

This discussion thread is closed

Replies have been disabled for this discussion.