1

我有这个代码:

protected void Page_Load(object sender, EventArgs e)
{
        SqlDataSource4.SelectParameters["zadavatel"].DefaultValue = this.Page.User.Identity.Name;
}

标记:

<InsertParameters>
    <asp:Parameter Name="zadavatel" Type="String" />
</InsertParameters>

<asp:SqlDataSource ID="SqlDataSource4" runat="server" 
     ConnectionString="<%$ ConnectionStrings:fotbalConnectionString %>" 
     DeleteCommand="DELETE Diskuze WHERE Id_Diskuze=@Id_Diskuze" 
     SelectCommand="SELECT * FROM [Diskuze] WHERE ([Id_Zapasu] = @Id_Zapasu) ORDER BY [Datum_Vytvoreni] ASC" 
     InsertCommand="INSERT INTO Diskuze (Autor, TextD, Ip_Adresa, Id_Zapasu) VALUES (@zadavatel, @TextD, '127.0.0.1', @Id_zapasu)">

我想将参数插入zadavatelAutor ...但我收到此错误:

System.NullReferenceException: Odkaz na objekt není nastaven na instanci objektu。(你调用的对象是空的。)

我不知道问题出在哪里:/

4

1 回答 1

1

您应该使用InsertParameters["@zadavatel"]而不是SelectParameters["zadavatel"].

于 2013-04-11T08:36:30.530 回答