0

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

    <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>

我不知道从这里去哪里

4

3 回答 3

3

这是此参考的摘录:

检查 SqlDataSource 对象中是否有任何已拉取或重命名的字段,其中包含空格。'_' 下划线可以正常工作,但是执行类似“Select [somename] as [Some Name] FROM [names] WHERE [id]=@id”这样的查询将导致上述错误

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

于 2012-08-03T20:06:44.673 回答
2

删除 Bind 语句中字段名称周围的方括号,例如

     <asp:TextBox ID="Job_TitleTextBox" runat="server" 
         Text='<%# Bind("Job Title") %>' />

只有在 UpdateCommand 的查询部分才真正需要括号,以允许字段名称中存在空格。括号会在 ASP.NET 构建页面时生成的后台代码中引起各种奇怪的混淆。希望有帮助。

于 2012-08-03T20:12:05.890 回答
0

我通过将表中字段的所有名称更改为一个单词或用下划线分隔的单词(例如 first_name),然后更改更新代码以使用新名称,从而在我的项目中修复了此错误。

于 2014-08-22T19:46:15.887 回答