Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Must declare scalar variable @ID

Author  Topic 

shruthi_R
Starting Member

10 Posts

Posted - 2007-03-24 : 04:54:49
the following is my code
can anybody rectify my problem that i get when running my application
"Must declare scalar variable @ID"
<asp:GridView ID="GridView1" DataKeyNames="ID" runat="server" AutoGenerateColumns="False" BackImageUrl="~/App_Themes/SkinFile/back1.jpg"
BorderColor="Teal" BorderStyle="Solid" DataSourceID="SqlDataSource1">
<Columns>
<asp:CommandField ButtonType="Button" ShowSelectButton="True" />
<asp:BoundField DataField="ID" HeaderText="ID" SortExpression="ID" />
<asp:BoundField DataField="Answers" HeaderText="Answers" SortExpression="Answers" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:YahooConnectionString7 %>"
DeleteCommand="DELETE FROM Answers WHERE (ID = @ID)" InsertCommand="INSERT INTO Answers(ID, Answers) VALUES (@ID, @Answers)"
SelectCommand="SELECT Answers.* FROM Answers" UpdateCommand="UPDATE Answers SET ID = @ID, Answers = @Answers WHERE (ID = @ID)">
<DeleteParameters>
<asp:Parameter Name="ID" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="ID" />
<asp:Parameter Name="Answers" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="ID" />
<asp:Parameter Name="Answers" />
</InsertParameters>
</asp:SqlDataSource>

sachinsamuel
Constraint Violating Yak Guru

383 Posts

Posted - 2007-03-24 : 06:14:47
I can't see the variable declaration, in the code.


1) DELETE FROM Answers WHERE (ID = @ID)
2) INSERT INTO Answers(ID, Answers) VALUES (@ID, @Answers)

Create stored procedure to execute above queries. You can pass parameter (@ID and @Answers) to the storedprocedure and execute them .

If you don't want to create stored procedures then you have to send the values and not the variable.

Like
DELETE FROM Answers WHERE (ID = 1)
INSERT INTO Answers(ID, Answers) VALUES (1, 'Test Answer')


Thanks
Sachin


Don't sit back because of failure. It will come back to check if you still available. -- Binu
Go to Top of Page
   

- Advertisement -