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

Discussion in 'ASP .Net' started by Chapi, May 26, 2008.

  1. Chapi

    Chapi Guest

    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.DataGridPageChangedEventArgs)
    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.
    Chapi, May 26, 2008
    #1
    1. Advertising

  2. Chapi

    Jeff Winn Guest

    Re: Specified argument was out of the range of valid values.Parameter name: index

    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" <> wrote in message
    news:...
    > 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.DataGridPageChangedEventArgs)
    > 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.
    Jeff Winn, May 26, 2008
    #2
    1. Advertising

  3. Chapi

    Chapi Guest

    On 26 mayo, 13:11, "Jeff Winn" <> wrote:
    > 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" <> wrote in message
    >
    > news:...
    >
    > > 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.DataGridPageChangedEventArgs)
    > > 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.
    Chapi, May 26, 2008
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Todd Perkins
    Replies:
    0
    Views:
    9,369
    Todd Perkins
    Sep 15, 2004
  2. subdhar
    Replies:
    9
    Views:
    27,782
    Subhashish Dhar
    Nov 9, 2004
  3. darrel
    Replies:
    0
    Views:
    8,357
    darrel
    Aug 14, 2006
  4. Dave
    Replies:
    0
    Views:
    1,722
  5. Dave
    Replies:
    11
    Views:
    817
    Jesse Houwing
    Jul 9, 2006
Loading...

Share This Page