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

[亡魂溺海] 提交于 2019-12-02 08:06:40

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)

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!