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();
}
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
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...