0
votes

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>

I am not sure where to go from here

3
Can you reduce the size of your sample code to the specific area that is causing issuesCodeman
It never ceases to amaze me that some new users expect us to imagine the code that they are using and provide no code sample whatsoever and some new users do the exact opposite and dump their whole project in here and expect us to find out what goes wrong where. :)Bazzz
I reduced it by removing the gridview. I apologize for dumping the code in. I am having issues updating it with the form view. Where exactly in the form view I am not sure.user1374985

3 Answers

3
votes

Here's an excerpt from this reference:

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

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

2
votes

Remove the square brackets around the field names in your Bind statements, eg

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

The brackets are really necessary only in the query portion of the UpdateCommand to allow for the presence of spaces in the field names. The brackets can cause all kinds of strange confusion in the background code ASP.NET generates when building the page. Hope that helps.

0
votes

I fixed this error in my project by changing all the names of the fields in my table to one word, or words separated by underlines (e.g. first_name), then changing the update code to use the new names.