Reputation: 362
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
Upvotes: 0
Views: 164
Reputation: 15578
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. =)
Upvotes: 5
Reputation: 16524
Try this:
Insert into BasicData ([Id],[First name],[Last name],[std]) values (@sid,@firstname,@lastname,@std)
Upvotes: 0
Reputation: 1801
It is not a good pratice. But you could use [] for the collumn names.
Ex. ", [First Name], [Segond Name]," and so on..
Upvotes: 3