473,385 Members | 1,727 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Specified argument was out of the range of valid values.Parameter

hi, i'm having problems with a datagrid paging.
it's populates fine, but when i click the paging button appears this
error:"Specified argument was out of the range of valid
values.Parameter name: index"

I paste the code here in case someone can help me.

Sub paginaNueva(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridPageChangedEvent Args)
DataGrid1.CurrentPageIndex = e.NewPageIndex
binddata()
End Sub

Sub binddata()
Dim myConnection As New
System.Data.SqlClient.SqlConnection("myconnection_ string")
Dim strSQL As String = "SELECT * FROM
SISTEMAS_SIOPELMEETING_FOTOS WHERE titulo LIKE '%'+'almuerzos'+'%'"
Dim strSQL2 As String = "SELECT * FROM
SISTEMAS_SIOPELMEETING_FOTOS WHERE titulo LIKE
'%'+'presentaciones'+'%'"
Dim strSQL3 As String = "SELECT * FROM
SISTEMAS_SIOPELMEETING_FOTOS WHERE titulo LIKE '%'+'hotel'+'%'"
Dim strSQL4 As String = "SELECT * FROM
SISTEMAS_SIOPELMEETING_FOTOS WHERE titulo LIKE '%'+'estancia'+'%'"
Dim myCommand As New System.Data.SqlClient.SqlCommand(strSQL,
myConnection)
Dim myCommand2 As New
System.Data.SqlClient.SqlCommand(strSQL2, myConnection)
Dim myCommand3 As New
System.Data.SqlClient.SqlCommand(strSQL3, myConnection)
Dim myCommand4 As New
System.Data.SqlClient.SqlCommand(strSQL4, myConnection)
Dim myAdapter As New
System.Data.SqlClient.SqlDataAdapter(myCommand)
Dim myAdapter2 As New
System.Data.SqlClient.SqlDataAdapter(myCommand2)
Dim myAdapter3 As New
System.Data.SqlClient.SqlDataAdapter(myCommand3)
Dim myAdapter4 As New
System.Data.SqlClient.SqlDataAdapter(myCommand4)
Dim ds As New System.Data.DataSet()
Dim ds2 As New System.Data.DataSet()
Dim ds3 As New System.Data.DataSet()
Dim ds4 As New System.Data.DataSet()
myAdapter.Fill(ds)
myAdapter2.Fill(ds2)
myAdapter3.Fill(ds3)
myAdapter4.Fill(ds4)
DataGrid1.DataSource = ds
Datagrid2.DataSource = ds2
Datagrid3.DataSource = ds3
Datagrid4.DataSource = ds4
DataGrid1.DataBind()
Datagrid2.DataBind()
Datagrid3.DataBind()
Datagrid4.DataBind()
myConnection.Close()
End Sub

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
binddata()
End If
End Sub

Thanks.
Jun 27 '08 #1
2 3075
This response doesn't have anything to do with what your question was about,
but i feel that the issue must be addressed. I see below from your code
example that you're starting to build build dynamic sql statements within
your application.

Before you continue any further, you should read this article on SQL
injection:
http://msdn.microsoft.com/en-us/library/ms161953.aspx

You should avoid using dynamic sql statements like you would avoid getting
the black plague. Parameterized statements are a much better approach and
much more secure than simply concatenating strings together. You're exposing
your application to all sorts of problems doing what you're doing below. As
for your problem, the error tells you what the problem is - and if you read
the stack trace it will more than likely tell you the exact line that is
causing the problem.

That error means you're trying to use something that the application doesn't
want. If the application expects a value from 0 to 2, and you pass in a 4
that's the exception that will get thrown. Look at the stack trace or post
more information about the error if you want a more definitive answer. The
amount of information you've given us isn't enough to give you a specific
answer to fix your problem.

"Chapi" <ds*******@gmail.comwrote in message
news:8e**********************************@34g2000h sf.googlegroups.com...
hi, i'm having problems with a datagrid paging.
it's populates fine, but when i click the paging button appears this
error:"Specified argument was out of the range of valid
values.Parameter name: index"

I paste the code here in case someone can help me.

Sub paginaNueva(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridPageChangedEvent Args)
DataGrid1.CurrentPageIndex = e.NewPageIndex
binddata()
End Sub

Sub binddata()
Dim myConnection As New
System.Data.SqlClient.SqlConnection("myconnection_ string")
Dim strSQL As String = "SELECT * FROM
SISTEMAS_SIOPELMEETING_FOTOS WHERE titulo LIKE '%'+'almuerzos'+'%'"
Dim strSQL2 As String = "SELECT * FROM
SISTEMAS_SIOPELMEETING_FOTOS WHERE titulo LIKE
'%'+'presentaciones'+'%'"
Dim strSQL3 As String = "SELECT * FROM
SISTEMAS_SIOPELMEETING_FOTOS WHERE titulo LIKE '%'+'hotel'+'%'"
Dim strSQL4 As String = "SELECT * FROM
SISTEMAS_SIOPELMEETING_FOTOS WHERE titulo LIKE '%'+'estancia'+'%'"
Dim myCommand As New System.Data.SqlClient.SqlCommand(strSQL,
myConnection)
Dim myCommand2 As New
System.Data.SqlClient.SqlCommand(strSQL2, myConnection)
Dim myCommand3 As New
System.Data.SqlClient.SqlCommand(strSQL3, myConnection)
Dim myCommand4 As New
System.Data.SqlClient.SqlCommand(strSQL4, myConnection)
Dim myAdapter As New
System.Data.SqlClient.SqlDataAdapter(myCommand)
Dim myAdapter2 As New
System.Data.SqlClient.SqlDataAdapter(myCommand2)
Dim myAdapter3 As New
System.Data.SqlClient.SqlDataAdapter(myCommand3)
Dim myAdapter4 As New
System.Data.SqlClient.SqlDataAdapter(myCommand4)
Dim ds As New System.Data.DataSet()
Dim ds2 As New System.Data.DataSet()
Dim ds3 As New System.Data.DataSet()
Dim ds4 As New System.Data.DataSet()
myAdapter.Fill(ds)
myAdapter2.Fill(ds2)
myAdapter3.Fill(ds3)
myAdapter4.Fill(ds4)
DataGrid1.DataSource = ds
Datagrid2.DataSource = ds2
Datagrid3.DataSource = ds3
Datagrid4.DataSource = ds4
DataGrid1.DataBind()
Datagrid2.DataBind()
Datagrid3.DataBind()
Datagrid4.DataBind()
myConnection.Close()
End Sub

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
binddata()
End If
End Sub

Thanks.
Jun 27 '08 #2
On 26 mayo, 13:11, "Jeff Winn" <jw...@nospam.comwrote:
This response doesn't have anything to do with what your question was about,
but i feel that the issue must be addressed. I see below from your code
example that you're starting to build build dynamic sql statements within
your application.

Before you continue any further, you should read this article on SQL
injection:http://msdn.microsoft.com/en-us/library/ms161953.aspx

You should avoid using dynamic sql statements like you would avoid getting
the black plague. Parameterized statements are a much better approach and
much more secure than simply concatenating strings together. You're exposing
your application to all sorts of problems doing what you're doing below. As
for your problem, the error tells you what the problem is - and if you read
the stack trace it will more than likely tell you the exact line that is
causing the problem.

That error means you're trying to use something that the application doesn't
want. If the application expects a value from 0 to 2, and you pass in a 4
that's the exception that will get thrown. Look at the stack trace or post
more information about the error if you want a more definitive answer. The
amount of information you've given us isn't enough to give you a specific
answer to fix your problem.

"Chapi" <dspina...@gmail.comwrote in message

news:8e**********************************@34g2000h sf.googlegroups.com...
hi, i'm having problems with a datagrid paging.
it's populates fine, but when i click the paging button appears this
error:"Specified argument was out of the range of valid
values.Parameter name: index"
I paste the code here in case someone can help me.
Sub paginaNueva(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridPageChangedEvent Args)
DataGrid1.CurrentPageIndex = e.NewPageIndex
binddata()
End Sub
Sub binddata()
Dim myConnection As New
System.Data.SqlClient.SqlConnection("myconnection_ string")
Dim strSQL As String = "SELECT * FROM
SISTEMAS_SIOPELMEETING_FOTOS WHERE titulo LIKE '%'+'almuerzos'+'%'"
Dim strSQL2 As String = "SELECT * FROM
SISTEMAS_SIOPELMEETING_FOTOS WHERE titulo LIKE
'%'+'presentaciones'+'%'"
Dim strSQL3 As String = "SELECT * FROM
SISTEMAS_SIOPELMEETING_FOTOS WHERE titulo LIKE '%'+'hotel'+'%'"
Dim strSQL4 As String = "SELECT * FROM
SISTEMAS_SIOPELMEETING_FOTOS WHERE titulo LIKE '%'+'estancia'+'%'"
Dim myCommand As New System.Data.SqlClient.SqlCommand(strSQL,
myConnection)
Dim myCommand2 As New
System.Data.SqlClient.SqlCommand(strSQL2, myConnection)
Dim myCommand3 As New
System.Data.SqlClient.SqlCommand(strSQL3, myConnection)
Dim myCommand4 As New
System.Data.SqlClient.SqlCommand(strSQL4, myConnection)
Dim myAdapter As New
System.Data.SqlClient.SqlDataAdapter(myCommand)
Dim myAdapter2 As New
System.Data.SqlClient.SqlDataAdapter(myCommand2)
Dim myAdapter3 As New
System.Data.SqlClient.SqlDataAdapter(myCommand3)
Dim myAdapter4 As New
System.Data.SqlClient.SqlDataAdapter(myCommand4)
Dim ds As New System.Data.DataSet()
Dim ds2 As New System.Data.DataSet()
Dim ds3 As New System.Data.DataSet()
Dim ds4 As New System.Data.DataSet()
myAdapter.Fill(ds)
myAdapter2.Fill(ds2)
myAdapter3.Fill(ds3)
myAdapter4.Fill(ds4)
DataGrid1.DataSource = ds
Datagrid2.DataSource = ds2
Datagrid3.DataSource = ds3
Datagrid4.DataSource = ds4
DataGrid1.DataBind()
Datagrid2.DataBind()
Datagrid3.DataBind()
Datagrid4.DataBind()
myConnection.Close()
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
binddata()
End If
End Sub
Thanks.
Hi Jeff!
Thanks for the answer, you where totally right.
Jun 27 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Michael Conroy | last post by:
Hi... Synposis... Throws exception: "Specified argument was out of the range of valid values." Read on for the juicy tidbits. MySimpleClassCol mscc=new MySimpleClassCol(); private void...
4
by: Todd Perkins | last post by:
Hello all, surprisingly enough, this is my first newsgroup post, I usually rely on google. So I hope I have enough info contained. Thank you in advance for any help! Problem: I am getting...
9
by: subdhar | last post by:
I'm getting following error in asp.net application.I search the web and couldn't find error like this can any one help me in trouble with this error Specified argument was out of the range of...
5
by: pcnerd | last post by:
I'm trying to create a program that plots randomly colored pixels on a bitmap & then displays the bitmap. When I run the program, I see the pixels being plotted down the left side of the form. When...
0
by: darrel | last post by:
What does this error mean? Specified argument was out of the range of valid values. Parameter name: value System.Web It's being thrown here: DDL_SubCategory.Enabled = True...
0
by: rajarameshvarma | last post by:
Hi.... I have a serious problem while deploying my asp.net application. I have developed a web project in which everypage contains Header, Left navigation and footer as usercontrols. For center...
1
by: IndiraPriyaDarshini | last post by:
Hi , Am trying to sum the total in the footer if a gridview, but am getting the error "Specified argument was out of the range of valid values. Parameter name: index "..Its Printing one cell value...
6
by: rhepsi | last post by:
Hi All... I Came across this error while populating a combobox from a datatable (I'm working in VB.NET): Specified argument was out of the range of valid values. Parameter name: '-1' is not a...
0
by: gsauns | last post by:
I have a DetailsView which is inside of a FormView. I lifted this DetailsView straight off another one of my pages, where it was working beautifully. Now I get this endlessly frustrating error...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.