我在默认插入模式下有一个formview,当单击插入按钮时,它会将信息插入到sql数据库中,然后返回新插入的记录,并通过存储过程将其重定向到另一个表单视图中的新页面。以下是SqlDatasource的第1页的代码:
<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>
以下是第1页背后的代码:
protected void BiddersDB_Inserted(object sender, SqlDataSourceStatusEventArgs e)
{
int Id;
Id = (int)e.Command.Parameters["@Id"].Value;
Response.Redirect("Details.aspx?Id=" + Id);
}
以下是第2页的SqlDataSource代码:
<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>
我不断收到此错误消息&#34;类型&#39; System.NullReferenceException&#39;发生在BiddersWebVersion.dll中但未在用户代码中处理附加信息:对象引用未设置为对象的实例。&#34;
请帮忙。我几乎没有开始学习这个。感谢。