I have a gridview which populates pending membership applications. I want the button "Approve" to run the stored procedure in the code behind which inserts the application record into a client table and then deletes the record in the application table. (I've already tested and verified that the procedure works). Below is the code I am using in the Code Behind, and it's throwing the error "Object reference not set to an instance of an object". (on line 18 below)
I am including the relevant code below. I know there's something that I'm missing, but I just can't seem to see it.
Thanks for taking the time to look at it and help me out.
Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As GridViewCommandEventArgs)
If e.CommandName = "approve" Then
Dim con As New SqlConnection()
con.ConnectionString = ConfigurationManager.ConnectionStrings("MyConnectionString").ConnectionString
Dim cmd As New SqlCommand
cmd.CommandType = CommandType.StoredProcedure
cmd.Connection = con
cmd.CommandTimeout = 10000
Dim appID As Label = CType(GridView1.FindControl("id"), Label)
cmd.CommandText = "appAprove"
cmd.Parameters.Add("@id", SqlDbType.Int).Value = appID.Text
Catch exc As System.Exception
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
CellPadding="4" CssClass="dataTablesXSm" DataKeyNames="id"
DataSourceID="adminApps" ForeColor="#333333" GridLines="None" Width="1000px"
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<asp:Button ID="Button2" Text="APPROVE" runat="server" CommandName="approve" />