Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

INSERT INTO with InsertParameters: Must declare the variable XXX

0 views
Skip to first unread message

seanmatt...@hotmail.com

unread,
Apr 23, 2008, 7:55:00 AM4/23/08
to
Hi

What's wrong with this code, i keep getting an error "Must declar the
variable @MyTitle"

Thanks

-----HTML CODE-----
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:Conn1%>"
InsertCommand="INSERT INTO Links(Title) VALUES (@MyTitle)">
<InsertParameters>
<asp:ControlParameter PropertyName="text" ControlID="txtWebsiteTitle"
Name="@MyTitle" Type="String" />
</InsertParameters>
</asp:SqlDataSource>
<asp:TextBox text="XXXXXXXXXXXtitle from default" runat="server"
id="txtWebsiteTitle" />
<asp:Button id="btnLinkExchange" onclick="btnLinkExchange_click"
runat="server" Text="Submit Link" />

-----CODEBEHIND-----
protected void btnLinkExchange_click(object sender,
System.EventArgs e)
{
SqlDataSource1.Insert();
}

Manish

unread,
Apr 23, 2008, 10:14:01 AM4/23/08
to
Hi,

I dont see anything wrong with the code. Please refer to the link below for
inserting rows in database using SqlDatasource control.

http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.sqldatasource.insert.aspx

Regards,
Manish
www.componentOne.com

Fernando Rodriguez

unread,
Apr 27, 2008, 12:10:25 PM4/27/08
to
The problem is the @ sign before the param name on your ControlParameter
tag.

basically your command is generating the following SQL code:

DECLARE @@MyTitle as nvarchar(max)
SET @@MyTitle = '<param value>'


INSERT INTO Links(Title) VALUES (@MyTitle)

if you run that code you'll get that error because you declared @@MyTitle
but instead you're trying to use @MyTitle, so either remove the @ sign from
the ControlParameter (recommended) or add another @ to the INSERT statement.

"Manish" <Man...@discussions.microsoft.com> wrote in message
news:A0727093-7CA5-4492...@microsoft.com...

0 new messages