我有这段代码:
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)">
我想要插入参数zadavatel
到Autor ...但我收到此错误:
System.NullReferenceException:Odkaz naobjektnenínastavenna instanci objektu。 (对象引用未设置为对象的实例。)
我不知道问题出在哪里:/
答案 0 :(得分:1)
您应该使用InsertParameters["@zadavatel"]
代替SelectParameters["zadavatel"]
。