开发者

Sql Command Error (Asp.net)

开发者 https://www.devze.com 2023-03-20 21:21 出处:网络
I Get Error when i use the following code str = \"Insert into 开发者_如何学运维BasicData (Id,First name,Last name,std) values (@sid,@firstname,@lastname,@std)\"

I Get Error when i use the following code

str = "Insert into 开发者_如何学运维BasicData (Id,First name,Last name,std) values (@sid,@firstname,@lastname,@std)"

The Error i get is Near Name

But when i remove spaces between First name

If i make it

str = "Insert into BasicData (Id,Firstname,Lastname,std) values (@sid,@firstname,@lastname,@std)"

The error goes away.... I gave column names First Name in the Database's Table( I also changed it to Firstname-so the error went away)

So does Sql Database permit you to have Spaces in Column Names??? If it does how should i write the sql insert statement


insert into basicdata (id, [First name], [Last name], std)
    values (@sid,@firstname,@lastname,@std)

Note the brackets, which will allow you to reference columns with spaces in their name. While this is not good practice, it's definitely allowed by the system. You should probably stay away from such design in the future though. Makes it harder to read. =)


It is not a good pratice. But you could use [] for the collumn names.

Ex. ", [First Name], [Segond Name]," and so on..


Try this:

Insert into BasicData ([Id],[First name],[Last name],[std]) values (@sid,@firstname,@lastname,@std)


column names with spaces must be wrapped in [brackets].

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号