asp.net - Still Getting 'Must Declare Scalar Variable' Error After Declaring It -


I am trying to write a few simple enough asp.NET code to manipulate data in a SQL Server 2012 database . I have done it hundred times before, but for some reason this is not working and it is driving me crazy.

I have the following code I loads the page and displays the data correctly I can record the records successfully by modifying the values ​​in textboxes and hitting the update button also can. But the Delete button will not work - every time I click on it, I get the error Scalar convertible @ PhoneNumberID should be declared. As you can see, I have included the variable in my DeleteParameters, and by the way I have declared it in my update permaters, that's fine! Id = "lblPersonID" runat = "server" text = "2" /> gt; & Lt; Br / & gt; & Lt; Br / & gt; & Lt; Asp: ListView id = "lvEditPhoneNumbers" runat = "server" DataSourceID = "SQLEditPhoneNumbers" & gt; & Lt; ItemTemplate & gt; & Lt; Asp: Label ID = "lblPhoneNumberID" runat = "server" text = '& lt;% # bind ("PhoneNumberID")% & gt; / & Gt; & Lt; Asp: DropDownList id = "ddlEditPhoneNumberType" runat = "server" DataSourceID = "SQLPhoneNumberType" DataTextField = "Description" DataValueField = "ID" SelectedValue = '& lt;% # Bind ("PhoneNumberTypeID")%> / & Gt; & Lt; Asp: SqlDataSource id = "SQLPhoneNumberType" runat = "server" connectionstring = "& lt;% $ connectionString: contact transit string% & gt;" SelectCommand = "SELECT * FROM [PhoneNumberType] WHERE [DELET] = 0" & gt; & Lt; / Asp: SqlDataSource & gt; & Lt; ASP: text box id = "txtEditPhoneNumber" runat = "server" text = '& lt;% # bind ("phone number")% & gt; CssClass = "contactdetailseditfield" /> & Lt; ASP: ImageButton ID = "BTN DellPhone" "Rootat =" Server "image URL =" ~ / Images / Trash-26 "width =" 15px "height =" 15px "tooltip =" Delete this phone number "commandname =" Remove "/ & gt; & Lt; Asp: button id = "btnUpdate" runat = "server" text = "update" commandName = "update" /> & Lt; / ItemTemplate & gt; & Lt; / ASP: ListView & gt; & Lt; Asp: SqlDataSource id = "SQLEditPhoneNumbers" runat = "server" connectionString = "& lt;% $ connectionStringings: ContactsInstitution string% & gt;" SelectCommand = "SELECT * FROM [PhoneNumbers] WHERE ([PersonID] = @PersonID) and ([deleted] = 0)" Update Command = "Update [phone number] SET [PhoneNumber] = @PhoneNumber, [PhoneNumberType] = @ PhoneNumberTypeID WHERE [ID] = @phoneNumberID) "Discount Command =" Update [Phone Number] SET [DELET] = 1 Where ([ID] = @phoneNumberID) "& gt; & Lt; SelectParameters & gt; & Lt; Asp: ControlParameter ControlID = "lblPersonID" name = "PersonID" property name = "text" type = "string" /> & Lt; / SelectParameters & gt; & Lt; DeleteParameters & gt; & Lt; Asp: parameter name = "phone number id" type = "int 32" /> & Lt; / DeleteParameters & gt; & Lt; UpdateParameters & gt; & Lt; Asp: parameter name = "phone number id" type = "int 32" /> & Lt; Asp: parameter name = "phone number" type = "string" /> & Lt; ASP: Parameter Name = "PhoneNumberTapID" Type = "Int 32" /> & Lt; / UpdateParameters & gt; & Lt; / ASP: SQLDataSource & gt;

Yes, I know that the way data is displayed is not beautiful - I took this code out of the page that is going to appear to reveal it And to understand what's going on. And yes, I know I have put the command UPDATE in the DeleteCommand , but I have no problems in the past (at least I think I have it) And anyway, it works if I consider paramaterised in command and change it with clearly declared value.

When you use the DeleteItem function of the data control (like ListView ) , The values ​​of the parameters need to be automatically banned to remove the property. Otherwise, even if you have identified PhoneNumberID as a parameter in the DeleteCommand , it is not really being provided with a value, so it is not Not declared:

  & lt; Asp: list view id = "lvEditPhoneNumbers" runat = "server" datasource id = "SQLEditPhoneNumbers" DataKeyNames = "PhoneNumberID" & gt; Add ^^^^^ this  

Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

lua - HowTo create a fuel bar -