Help: What is wrong with this code?

P

Progman

I am getting the error:

"[Microsoft][SQL Native Client][SQL Server]Must declare the scalar variable
"@UserComment".]"

The code:

<asp:FormView ID="FormView1" runat="server" BackColor="White"
BorderColor="White" DefaultMode="Insert"

BorderStyle="Ridge" BorderWidth="2px" CellPadding="3" CellSpacing="1"
DataSourceID="SqlDataSource1">

<FooterStyle BackColor="#C6C3C6" ForeColor="Black" />

<EditRowStyle BackColor="#9471DE" Font-Bold="True" ForeColor="White" />

<RowStyle BackColor="#DEDFDE" ForeColor="Black" />

<PagerStyle BackColor="#C6C3C6" ForeColor="Black" HorizontalAlign="Right" />

<InsertItemTemplate>

UserComment:

<asp:TextBox ID="UserCommentTextBox" runat="server" Text='<%#
Bind("UserComment") %>'></asp:TextBox><br />

<asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True"
CommandName="Insert"

Text="Insert"></asp:LinkButton>

<asp:LinkButton ID="InsertCancelButton" runat="server"
CausesValidation="False" CommandName="Cancel"

Text="Cancel"></asp:LinkButton>

</InsertItemTemplate>

<ItemTemplate>

UserComment:

<asp:Label ID="UserCommentLabel" runat="server" Text='<%#
Bind("UserComment") %>'></asp:Label><br />

</ItemTemplate>

<HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#E7E7FF" />

</asp:FormView>

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$
ConnectionStrings:VoteHelperConnectionString %>"

ProviderName="<%$ ConnectionStrings:VoteHelperConnectionString.ProviderName
%>"

DeleteCommand="DELETE FROM VoteHelper.dbo.VH_Data_GuestBook"

InsertCommand="INSERT INTO VoteHelper.dbo.VH_Data_GuestBook(UserComment)
VALUES (@UserComment)"

SelectCommand="SELECT [UserComment] FROM [VH_Data_GuestBook]"

UpdateCommand="UPDATE VoteHelper.dbo.VH_Data_GuestBook SET UserComment =
@UserComment">

<InsertParameters>

<asp:formparameter name="UserComment" formfield="UserCommentTextBox" />

</InsertParameters>

</asp:SqlDataSource>
 
C

Chris R. Timmons

Progman,

You're missing a section in <asp:SqlDataSource>. For the update
statement, an <UpdateParameters> section is needed just like you have
for <InsertParameters>:


<UpdateParameters>

<asp:formparameter name="UserComment"
formfield="UserCommentTextBox" />

</UpdateParameters>
 

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,995
Messages
2,570,230
Members
46,818
Latest member
Brigette36

Latest Threads

Top