' nvarchar'附近的语法不正确;必须在@num附近声明标量变量 [英] Incorrect syntax near 'nvarchar' must declare scalar variable near @num

查看:64
本文介绍了' nvarchar'附近的语法不正确;必须在@num附近声明标量变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我创建了一个项目,该项目的Formview绑定到Gridview.除了尝试更新表单视图时,其他所有命令似乎都可以正常工作,但标题中却出现错误.这是我的代码.

Hi all I created a project that has a Formview bound to a Gridview. All the other commands seem to work fine except when I try to update the form view I get the error in the title. Here is my code.

    <EditItemTemplate>
         num:

         <asp:TextBox ID="TextBox1" runat="server" 
             Text='<%# Bind("[num]") %>' />
         <br />   
         Job Title:
         <asp:TextBox ID="Job_TitleTextBox" runat="server" 
             Text='<%# Bind("[Job Title]") %>' />
         <br />
         Status:
         <asp:TextBox ID="StatusTextBox" runat="server" Text='<%# Bind("Status") %>' />
         <br />
         Department:
         <asp:TextBox ID="DepartmentTextBox" runat="server" 
             Text='<%# Bind("Department") %>' />
         <br />
         Date Position Available:
         <asp:TextBox ID="Date_Position_AvailableTextBox" runat="server" 
             Text='<%# Bind("[Date Position Available]") %>' />
         <br />
         Position Type:
         <asp:TextBox ID="Position_TypeTextBox" runat="server" 
             Text='<%# Bind("[Position Type]") %>' />
         <br />
         Job Duties:
         <asp:TextBox ID="Job_DutiesTextBox" runat="server" 
             Text='<%# Bind("[Job Duties]") %>' />

         <br />
         Qualifications:
         <asp:TextBox ID="QualificationsTextBox" runat="server" 
             Text='<%# Bind("Qualifications") %>' />
         <br />
         Physical Demands:
         <asp:TextBox ID="Physical_DemandsTextBox" runat="server" 
             Text='<%# Bind("[Physical Demands]") %>' />
         <br />
         Closing Date:
         <asp:TextBox ID="Closing_DateTextBox" runat="server" 
             Text='<%# Bind("[Closing Date]") %>' />
         <br />
         Hours Per Pay Period:
         <asp:TextBox ID="Hours_Per_Pay_PeriodTextBox" runat="server" 
             Text='<%# Bind("[Hours Per Pay Period]") %>' />
         <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>

    UpdateCommand="UPDATE [career_posting] SET [Job Title] = @Job_Title, [Status] = @Status, [Department] = @Department, [Date Position Available] = @Date_Position_Available, [Position Type] = @Position_Type, [Job Duties] = @Job_Duties, [Qualifications] = @Qualifications, [Physical Demands] = @Physical_Demands, [Closing Date] = @Closing_Date, [Hours Per Pay Period] = @Hours_Per_Pay_Period WHERE [num] = @num">

     <UpdateParameters>
         <asp:Parameter Name="Job_Title" Type="String" />
         <asp:Parameter Name="Status" Type="String" />
         <asp:Parameter Name="Department" Type="String" />
         <asp:Parameter Name="Date_Position_Available" Type="String" />
         <asp:Parameter Name="Position_Type" Type="String" />
         <asp:Parameter Name="Job_Duties" Type="String" />
         <asp:Parameter Name="Qualifications" Type="String" />
         <asp:Parameter Name="Physical_Demands" Type="String" />
         <asp:Parameter Name="Closing_Date" Type="String" />
         <asp:Parameter Name="Hours_Per_Pay_Period" Type="String" />
         <asp:Parameter Name="num" Type="Int32" />
     </UpdateParameters>
 </asp:SqlDataSource>

我不确定从这里去哪里

推荐答案

以下是

检查SqlDataSource对象中是否有您拉过或重命名的字段里面有空格.下划线"_"可以正常工作,但像这样的查询在[名称]中从[名称]中选择[某名称]作为[某名称][id] = @ id将导致上述错误

Check the SqlDataSource object for any fields you’ve pulled or renamed with spaces in them. An ‘_’ Underscore will work fine, but doing a query like this "Select [somename] as [Some Name] FROM [names] WHERE [id]=@id" will result in the above error

尝试用下划线替换所有空格(例如Job_Title)

Try replacing all the spaces with underscores (e.g. Job_Title)

这篇关于&amp;#39; nvarchar&#39;附近的语法不正确;必须在@num附近声明标量变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆