Pass id from one form to another form in another page with asp.net

1.3k views Asked by At

I have a formview in default insert mode that when the insert button is clicked it inserts information into a sql database then returns the newly inserted record and redirects it to a new page inside another form view via stored procedure. Here are the codes from page 1 of the SqlDatasource:

<asp:SqlDataSource ID="BiddersDB" runat="server" ConnectionString="<%$ ConnectionStrings:BiddersDatabaseConnection %>" InsertCommand="INSERT INTO [Bidders] ([Name], [Address], [City], [State], [Zip], [Phone], [Fax], [Email], [Status], [Notes], [MWBE]) VALUES (@Name, @Address, @City, @State, @Zip, @Phone, @Fax, @Email, @Status, @Notes, @MWBE); SET @Id = SCOPE_IDENTITY()" InsertCommandType="StoredProcedure" SelectCommand="SELECT * FROM [Bidders]" UpdateCommand="UPDATE [Bidders] SET [Name] = @Name, [Address] = @Address, [City] = @City, [State] = @State, [Zip] = @Zip, [Phone] = @Phone, [Fax] = @Fax, [Status] = @Status, [MWBE] = @MWBE, [Notes] = @Notes WHERE [Id] = @Id" OnInserted="BiddersDB_Inserted">
            <InsertParameters>
                <asp:Parameter Name="Name" />
                <asp:Parameter Name="Address" />
                <asp:Parameter Name="City" />
                <asp:Parameter Name="State" />
                <asp:Parameter Name="Zip" />
                <asp:Parameter Name="Phone" />
                <asp:Parameter Name="Fax" />
                <asp:Parameter Name="Email" />
                <asp:Parameter Name="Status" />
                <asp:Parameter Name="Notes" />
                <asp:Parameter Name="MWBE" />
                <asp:Parameter Name="Id" Direction="Output" Type="Int32"/>
            </InsertParameters>
            <UpdateParameters>
                <asp:Parameter Name="Name" />
                <asp:Parameter Name="Address" />
                <asp:Parameter Name="City" />
                <asp:Parameter Name="State" />
                <asp:Parameter Name="Zip" />
                <asp:Parameter Name="Phone" />
                <asp:Parameter Name="Fax" />
                <asp:Parameter Name="Status" />
                <asp:Parameter Name="MWBE" />
                <asp:Parameter Name="Notes" />
                <asp:Parameter Name="Id" />
            </UpdateParameters>
        </asp:SqlDataSource>

Here is the code behind from the page 1:

protected void BiddersDB_Inserted(object sender, SqlDataSourceStatusEventArgs e)
    {
        int Id;
        Id = (int)e.Command.Parameters["@Id"].Value;

        Response.Redirect("Details.aspx?Id=" + Id);
    }

Here are the SqlDataSource codes from page 2:

<asp:SqlDataSource ID="FormViewDB" runat="server" ConnectionString="<%$ ConnectionStrings:BiddersDatabaseConnection %>" 
        SelectCommand="SELECT Bidders.Id, Bidders.Name, Bidders.Address, Bidders.City, Bidders.State, Bidders.Zip, Bidders.Phone, Bidders.Fax, Bidders.Status, Bidders.Notes, Bidders.Email, Bidders.MWBE AS MWBEID, MWBE_Types.Code AS MWBE FROM Bidders INNER JOIN MWBE_Types ON Bidders.MWBE = MWBE_Types.MWBEID WHERE ([Id] like @ID) AND (Bidders.Name like @Name)"
        UpdateCommand="UPDATE [Bidders] SET [Name] = @Name, [Address] = @Address, [City] = @City, [State] = @State, [Zip] = @Zip, [Phone] = @Phone, [Fax] = @Fax, [Email]=@Email, [Status] = @Status, [MWBE]=@MWBEID, [Notes] = @Notes, [Denied] = @Denied WHERE [Id] = @Id"
        DeleteCommand="DELETE FROM [Bidders] WHERE [Id] = @Id"
        InsertCommand="INSERT INTO [Bidders] ([Name], [Address], [City], [State], [Zip], [Phone], [Fax], [Email], [Status], [MWBE], [Notes], [Denied]) VALUES (@Name, @Address, @City, @State, @Zip, @Phone, @Fax, @Email, @Status, @MWBE, @Notes, @Denied)">

            <UpdateParameters>
                <asp:Parameter Name="Name" Type="String" />
                <asp:Parameter Name="Address" Type="String" />
                <asp:Parameter Name="City" Type="String" />
                <asp:Parameter Name="State" Type="String" />
                <asp:Parameter Name="Zip" Type="String" />
                <asp:Parameter Name="Phone" Type="String" />
                <asp:Parameter Name="Fax" Type="String" />
                <asp:Parameter Name="Email" />
                <asp:Parameter Name="Status" Type="String" />
                <asp:Parameter Name="MWBEID" />
                <asp:Parameter Name="Notes" Type="String" />
                <asp:Parameter Name="Denied" Type="String" />
                <asp:Parameter Name="Id" Type="Int32" />
            </UpdateParameters>
            <InsertParameters>
                <asp:Parameter Name="Name" Type="String" />
                <asp:Parameter Name="Address" Type="String" />
                <asp:Parameter Name="City" Type="String" />
                <asp:Parameter Name="State" Type="String" />
                <asp:Parameter Name="Zip" Type="String" />
                <asp:Parameter Name="Phone" Type="String" />
                <asp:Parameter Name="Fax" Type="String" />
                <asp:Parameter Name="Email" />
                <asp:Parameter Name="Status" Type="String" />
                <asp:Parameter Name="MWBE"/>
                <asp:Parameter Name="Notes" Type="String" />
                <asp:Parameter Name="Denied" Type="String" />
            </InsertParameters>
            <DeleteParameters>
                <asp:Parameter Name="Id" Type="Int32" />
            </DeleteParameters>
        <SelectParameters>
            <asp:QueryStringParameter DefaultValue="%" Name="Id" QueryStringField="Id" Type="Int32" />
            <asp:QueryStringParameter DefaultValue="%" Name="Name" QueryStringField="Name" Type="String" />
        </SelectParameters>
        </asp:SqlDataSource>

I keep getting this error message "An exception of type 'System.NullReferenceException' occurred in BiddersWebVersion.dll but was not handled in user code Additional information: Object reference not set to an instance of an object."

Please help. I barely started learning this. Thanks.

0

There are 0 answers