O
officegeek
I have a gridview that is populated via page_load. I can get the
delete to work but get an error after it deletes. The error is below
the index value that is returned is the one that is deleted so that is
why I think I get an error. Any help would be great. I am in the
process of moving from classic ASP to .NET so i am not well versed
yet.
Index was out of range. Must be non-negative and less than the size of
the collection. Parameter name: index
Below is the codebehind
Protected Sub DeleteRow(ByVal sender As Object, ByVal e As
GridViewCommandEventArgs)
Try
Dim index As Integer = Convert.ToInt32(e.CommandArgument)
Dim selectedRow As GridViewRow =
DirectCast(e.CommandSource, GridView).Rows(index)
If e.CommandName = "deletefeed" Then
Dim feedid As String = selectedRow.Cells(0).Text
Dim strSQL As String = "delete from xmlfeeds where
xmlfeedid=" & feedid
Dim DBConnClient As New OleDbConnection(strConnString)
Dim cmd As New OleDbCommand(strSQL, DBConnClient)
cmd.Connection.Open()
cmd.ExecuteNonQuery()
cmd.Connection.Close()
errormessage.Text = "The XML Feed was deleted!"
End If
Catch ex As Exception
errormessage.Text = ex.Message
End Try
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Dim strSQL As String = "Select * from xmlfeeds where
xmlfeedstatus=0"
Dim DBConnClient As New OleDbConnection(strConnString)
Dim cmd As New OleDbCommand(strSQL, DBConnClient)
cmd.Connection.Open()
Try
Dim GetXMLFeeds As OleDbDataReader = cmd.ExecuteReader()
GridView1.DataSource = GetXMLFeeds
DataBind()
GetXMLFeeds.Close()
Catch ex As Exception
errormessage.Text = ex.Message
Finally
cmd.Connection.Close()
End Try
End Sub
delete to work but get an error after it deletes. The error is below
the index value that is returned is the one that is deleted so that is
why I think I get an error. Any help would be great. I am in the
process of moving from classic ASP to .NET so i am not well versed
yet.
Index was out of range. Must be non-negative and less than the size of
the collection. Parameter name: index
Below is the codebehind
Protected Sub DeleteRow(ByVal sender As Object, ByVal e As
GridViewCommandEventArgs)
Try
Dim index As Integer = Convert.ToInt32(e.CommandArgument)
Dim selectedRow As GridViewRow =
DirectCast(e.CommandSource, GridView).Rows(index)
If e.CommandName = "deletefeed" Then
Dim feedid As String = selectedRow.Cells(0).Text
Dim strSQL As String = "delete from xmlfeeds where
xmlfeedid=" & feedid
Dim DBConnClient As New OleDbConnection(strConnString)
Dim cmd As New OleDbCommand(strSQL, DBConnClient)
cmd.Connection.Open()
cmd.ExecuteNonQuery()
cmd.Connection.Close()
errormessage.Text = "The XML Feed was deleted!"
End If
Catch ex As Exception
errormessage.Text = ex.Message
End Try
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Dim strSQL As String = "Select * from xmlfeeds where
xmlfeedstatus=0"
Dim DBConnClient As New OleDbConnection(strConnString)
Dim cmd As New OleDbCommand(strSQL, DBConnClient)
cmd.Connection.Open()
Try
Dim GetXMLFeeds As OleDbDataReader = cmd.ExecuteReader()
GridView1.DataSource = GetXMLFeeds
DataBind()
GetXMLFeeds.Close()
Catch ex As Exception
errormessage.Text = ex.Message
Finally
cmd.Connection.Close()
End Try
End Sub