System.ArgumentOutOfRangeException

Discussion in 'ASP .Net Datagrid Control' started by leezard, Aug 20, 2003.

  1. leezard

    leezard Guest

    Specified argument was out of the range of valid values. Parameter name:
    index
    Exception Details: System.ArgumentOutOfRangeException: Specified argument
    was out of the range of valid values. Parameter name: index
    Below is my code:

    Sub MyDataGrid_EditCommand(s As Object, e As DataGridCommandEventArgs )
    MyDataGrid.EditItemIndex = e.Item.ItemIndex
    BindData
    End Sub
    Sub MyDataGrid_Cancel(Source As Object, E As DataGridCommandEventArgs)
    MyDataGrid.EditItemIndex = -1
    BindData()
    End Sub

    Sub MyDataGrid_UpdateCommand(s As Object, e As DataGridCommandEventArgs )
    Dim conn As SqlConnection
    Dim MyCommand As SqlCommand
    Dim strConn as string =
    "server=localhost;trusted_connection=true;database=PTG"
    Dim txtDate As textbox = E.Item.cells(2).Controls(0)
    Dim txtMorning As textbox = E.Item.cells(3).Controls(0)
    Dim txtAfternoon As textbox = E.Item.cells(4).Controls(0)
    Dim txtNight As textbox = E.Item.cells(5).Controls(0)
    Dim txtMin As textbox = E.Item.cells(6).Controls(0)
    Dim txtMax As textbox = E.Item.cells(7).Controls(0)
    Dim strUpdateStmt As String

    strUpdateStmt =" UPDATE Weather SET" & _
    " Date =@Date, morning =@morning, afternoon =@afternoon, night
    =@night, min =@min, max =@max" & _
    " WHERE wea_id = @wea_id "
    conn = New SqlConnection(strConn)
    MyCommand = New SqlCommand(strUpdateStmt, conn)
    MyCommand.Parameters.Add(New SQLParameter("@Date", txtDate.text))
    MyCommand.Parameters.Add(New SQLParameter("@morning",
    txtMorning.text))
    MyCommand.Parameters.Add(New SQLParameter("@afternoon",
    txtAfternoon.text))
    MyCommand.Parameters.Add(New SQLParameter("@night", txtNight.text))
    MyCommand.Parameters.Add(New SQLParameter("@min", txtMin.text))
    MyCommand.Parameters.Add(New SQLParameter("@max", txtMax.text))
    MyCommand.Parameters.Add(New SQLParameter("@wea_id",
    e.Item.Cells(1).Text ))
    conn.Open()
    MyCommand.ExecuteNonQuery()
    MyDataGrid.EditItemIndex = -1
    conn.close
    BindData
    End Sub

    Sub Page_Load(Source as Object, E as EventArgs)
    if not Page.IsPostBack then
    BindData
    end if
    End Sub
    Sub BindData()
    Dim strConn as string =
    "server=localhost;trusted_connection=true;database=PTG"
    Dim sql as string = "Select wea_id, Date, morning, afternoon, night, min,
    max from Weather"
    Dim conn as New SQLConnection(strConn)
    Dim objDR as SQLDataReader
    Dim Cmd as New SQLCommand(sql, conn)
    conn.Open()
    objDR=Cmd.ExecuteReader(system.data.CommandBehavior.CloseConnection)
    MyDataGrid.DataSource = objDR
    MyDataGrid.DataBind()
    conn.close
    End Sub

    Thanks in advance.
     
    leezard, Aug 20, 2003
    #1
    1. Advertising

  2. leezard

    leezard Guest

    I've figured it out.
    thanks for viewing. :)

    "leezard" <> wrote in message
    news:ODEgu%...
    > Specified argument was out of the range of valid values. Parameter name:
    > index
    > Exception Details: System.ArgumentOutOfRangeException: Specified argument
    > was out of the range of valid values. Parameter name: index
    > Below is my code:
    >
    > Sub MyDataGrid_EditCommand(s As Object, e As DataGridCommandEventArgs )
    > MyDataGrid.EditItemIndex = e.Item.ItemIndex
    > BindData
    > End Sub
    > Sub MyDataGrid_Cancel(Source As Object, E As DataGridCommandEventArgs)
    > MyDataGrid.EditItemIndex = -1
    > BindData()
    > End Sub
    >
    > Sub MyDataGrid_UpdateCommand(s As Object, e As DataGridCommandEventArgs )
    > Dim conn As SqlConnection
    > Dim MyCommand As SqlCommand
    > Dim strConn as string =
    > "server=localhost;trusted_connection=true;database=PTG"
    > Dim txtDate As textbox = E.Item.cells(2).Controls(0)
    > Dim txtMorning As textbox = E.Item.cells(3).Controls(0)
    > Dim txtAfternoon As textbox = E.Item.cells(4).Controls(0)
    > Dim txtNight As textbox = E.Item.cells(5).Controls(0)
    > Dim txtMin As textbox = E.Item.cells(6).Controls(0)
    > Dim txtMax As textbox = E.Item.cells(7).Controls(0)
    > Dim strUpdateStmt As String
    >
    > strUpdateStmt =" UPDATE Weather SET" & _
    > " Date =@Date, morning =@morning, afternoon =@afternoon, night
    > =@night, min =@min, max =@max" & _
    > " WHERE wea_id = @wea_id "
    > conn = New SqlConnection(strConn)
    > MyCommand = New SqlCommand(strUpdateStmt, conn)
    > MyCommand.Parameters.Add(New SQLParameter("@Date", txtDate.text))
    > MyCommand.Parameters.Add(New SQLParameter("@morning",
    > txtMorning.text))
    > MyCommand.Parameters.Add(New SQLParameter("@afternoon",
    > txtAfternoon.text))
    > MyCommand.Parameters.Add(New SQLParameter("@night",

    txtNight.text))
    > MyCommand.Parameters.Add(New SQLParameter("@min", txtMin.text))
    > MyCommand.Parameters.Add(New SQLParameter("@max", txtMax.text))
    > MyCommand.Parameters.Add(New SQLParameter("@wea_id",
    > e.Item.Cells(1).Text ))
    > conn.Open()
    > MyCommand.ExecuteNonQuery()
    > MyDataGrid.EditItemIndex = -1
    > conn.close
    > BindData
    > End Sub
    >
    > Sub Page_Load(Source as Object, E as EventArgs)
    > if not Page.IsPostBack then
    > BindData
    > end if
    > End Sub
    > Sub BindData()
    > Dim strConn as string =
    > "server=localhost;trusted_connection=true;database=PTG"
    > Dim sql as string = "Select wea_id, Date, morning, afternoon, night, min,
    > max from Weather"
    > Dim conn as New SQLConnection(strConn)
    > Dim objDR as SQLDataReader
    > Dim Cmd as New SQLCommand(sql, conn)
    > conn.Open()
    > objDR=Cmd.ExecuteReader(system.data.CommandBehavior.CloseConnection)
    > MyDataGrid.DataSource = objDR
    > MyDataGrid.DataBind()
    > conn.close
    > End Sub
    >
    > Thanks in advance.
    >
    >
     
    leezard, Aug 20, 2003
    #2
    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. =?Utf-8?B?SG96aQ==?=
    Replies:
    1
    Views:
    6,982
    Ken Cox [Microsoft MVP]
    Jun 2, 2004
  2. hari
    Replies:
    3
    Views:
    12,587
    Vimal
    Nov 15, 2006
  3. Replies:
    1
    Views:
    438
    Joshua Flanagan
    Dec 10, 2005
  4. loga123
    Replies:
    2
    Views:
    5,702
    loga123
    Jun 28, 2006
  5. J055
    Replies:
    4
    Views:
    7,951
    Steven Cheng[MSFT]
    Nov 14, 2007
Loading...

Share This Page