Reputation: 372
I have this code:
protected void Page_Load(object sender, EventArgs e)
{
SqlDataSource4.SelectParameters["zadavatel"].DefaultValue = this.Page.User.Identity.Name;
}
Markup:
<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)">
I want insert parameter zadavatel
to Autor...but I get this error:
System.NullReferenceException: Odkaz na objekt není nastaven na instanci objektu. (Object reference not set to an instance of an object.)
I donť know where is the problem :/
Upvotes: 1
Views: 650
Reputation: 11
You should use InsertParameters["@zadavatel"]
instead of SelectParameters["zadavatel"]
.
Upvotes: 1