Sqldatasource and InsertParameters from TextBox trouble

Joined
Jul 29, 2009
Messages
2
Reaction score
0
Hi,
I've been trying to send my parameters from textbox to sqldatasource but i always get "Must declare the scalar variable" message.
I tried several ways and this is what i got.

At button:

protected void Button1_Click(object sender, EventArgs e)
{
SqlDataSource2.InsertParameters.Add("@xlnam", xlnam);
SqlDataSource2.InsertParameters.Add("@xfnam", xfnam);
SqlDataSource2.InsertParameters.Add("@xstreet", xstreet);
SqlDataSource2.Insert();
}

at aspx:

<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox><br />
<br />
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
<br />
<asp:Label ID="Label2" runat="server" Text="Label" Width="568px"></asp:Label><br />
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:Connectionspainlink %>"
InsertCommand="INSERT INTO members(lnam, fnam, street1) VALUES (@xlnam,@xfnam,@xstreet)"
ProviderName="<%$ ConnectionStrings:Connectionspainlink.ProviderName %>" SelectCommand="SELECT id, fnam, lnam, street1 FROM members">
<InsertParameters>
<asp:ControlParameter ControlID="TextBox1" Name="xlnam" DefaultValue="@xlnam" PropertyName="Text" />
<asp:ControlParameter ControlID="TextBox2" Name="xfnam" DefaultValue="@xfnam" PropertyName="Text" />
<asp:ControlParameter ControlID="TextBox3" Name="xstreet" DefaultValue="@xstreet" PropertyName="Text" />
</InsertParameters>

</asp:SqlDataSource>
<asp:Button ID="Button1" runat="server" Text="Button" PostBackUrl="~/test.aspx" OnClick="Button1_Click" />


I cant use a form way cause i already got a form at MasterPage for the menu.
Can please some one help me to solve this? its dryving me crazy.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,920
Messages
2,570,038
Members
46,449
Latest member
onedumbsquirrel

Latest Threads

Top