Incorrect syntax near 'nvarchar' must declare scalar variable near @num

前端 未结 3 566
逝去的感伤
逝去的感伤 2021-01-28 06:36

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 tit

相关标签:
3条回答
  • 2021-01-28 06:42

    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.

    0 讨论(0)
  • 2021-01-28 06:45

    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 讨论(0)
  • 2021-01-28 06:55

    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)

    0 讨论(0)
提交回复
热议问题