Sqldatasource and InsertParameters from TextBox trouble

Jul 29, 2009
Reaction score
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);

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">
<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" />

<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