Must declare the scalar variable

Posted by Mike4ta under ASP.NET on 9/23/2009 | Views : 7535 | Status : [Member] | Replies : 3
I have been trying to get an update page to run. I keep getting the "Must declare the scalar variable "@HardwareInventoryID". " Error.
I get this for my select statement from my database. If I replace the Varable name in the select statement with a ? the select will work, but I still get the error when i submit updates.

<%@ Page Language="VB" %>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">

<asp:FormView ID="FormView1" runat="server" DataKeyNames="HardwareInventoryID" DataSourceID="SqlDataSource1">
<EditItemTemplate>
HardwareInventoryID:
<asp:Label ID="HardwareInventoryIDLabel1" runat="server" Text='<%# Eval("HardwareInventoryID") %>' />
<br />
Tracking_Num:
<asp:TextBox ID="Tracking_NumTextBox" runat="server" Text='<%# Bind("Tracking_Num") %>' />
<br />
Make:
<asp:TextBox ID="MakeTextBox" runat="server" Text='<%# Bind("Make") %>' />
<br />
Model:
<asp:TextBox ID="ModelTextBox" runat="server" Text='<%# Bind("Model") %>' />
<br />
Description:
<asp:TextBox ID="DescriptionTextBox" runat="server" Text='<%# Bind("Description") %>' />
<br />
<asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update" Text="Update" />
&nbsp;<asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" />
</EditItemTemplate>

<ItemTemplate>
HardwareInventoryID:
<asp:Label ID="HardwareInventoryIDLabel" runat="server" Text='<%# Eval("HardwareInventoryID") %>' />
<br />
Tracking_Num:
<asp:Label ID="Tracking_NumLabel" runat="server" Text='<%# Bind("Tracking_Num") %>' />
<br />
Make:
<asp:Label ID="MakeLabel" runat="server" Text='<%# Bind("Make") %>' />
<br />
Model:
<asp:Label ID="ModelLabel" runat="server" Text='<%# Bind("Model") %>' />
<br />
Description:
<asp:Label ID="DescriptionLabel" runat="server" Text='<%# Bind("Description") %>' />
<br />
<asp:LinkButton ID="EditButton" runat="server" CausesValidation="False" CommandName="Edit" Text="Edit" />
</ItemTemplate>

</asp:FormView>

<asp:SqlDataSource ID="SqlDataSource1" runat="server" connectionstring="<%$ ConnectionStrings:ITInventoryconnectionstring %>"
providerName="<%$ ConnectionStrings:ITInventoryconnectionstring.ProviderName %>"
SelectCommand="SELECT * FROM [Hardware_Inventory] WHERE ([HardwareInventoryID] = @HardwareInventoryID)"
UpdateCommand="UPDATE [Hardware_Inventory] SET [Tracking_Num] = @Tracking_Num, [Make] = @Make, [Model] = @Model, [Description] = @Description, WHERE [HardwareInventoryID] = @HardwareInventoryID">
<SelectParameters>
<asp:QueryStringParameter Name="HardwareInventoryID" QueryStringField="HardwareInventoryID" Type="Int32" />
</SelectParameters>

<UpdateParameters>
<asp:Parameter Name="Tracking_Num" Type="String" />
<asp:Parameter Name="Make" Type="String" />
<asp:Parameter Name="Model" Type="String" /




Responses

Posted by: Vuyiswamb on: 9/24/2009 [Member] [MVP] [Administrator] NotApplicable

Up
0
Down
Good Day Mike4ta

That Error means , you have not declared the Variable on your code. WEll i see you are using a SQLDAtasource, now My point is that you have variables , but where do they get the data and where are they Declared. Your Code is Complecated because you are using a Wizard to do database work for you. what the above error means , is that you are missing this line of Code

UpdateCommand.Parameters.Add("@Description", SqlDbType.VarChar, 63).Value = Pattern;

in this code the UpdateCommand is the Command Object, The Description is the name of your Paramer, and followed by the datatype and the Dimension, if its integer use 4 and the last part tells you where is the Value comming from. THe Variable Pattern is the one that could be carrying the Value. You have to do this for every Parameter you use.

Am sorry i will be leaving now. In South Africa(my country) its a Public holiday today, so i went to work because i forgot my cell phone.

Thank you for posting at Dotnetfunda

Vuyiswa Maseko



Thank you for posting at Dotnetfunda
[Administrator]

Mike4ta, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Mike4ta on: 9/24/2009 [Member] Starter

Up
0
Down
Thank you for your help. I think it was a .net framework version error. I was using .net 2 and I went trough the Visual Web Developer 2008 and it told me that my .Net version could be updated. I did this and got my page to work.


Once again thank you for your help.

Mike4ta, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vuyiswamb on: 9/24/2009 [Member] [MVP] [Administrator] NotApplicable

Up
0
Down
Thank you for posting at dotnetfunda

Vuyiswa Maseko

Thank you for posting at Dotnetfunda
[Administrator]

Mike4ta, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response