0

I created an ASP.NET MVC 4 application using Visual Studio 2012. The application is just normal and I did nothing fancy. Indeed no-coding at all.

(The default app seems to be using Localdb, simple membership implemented using AccountController)

I ran the application, clicked Register and created a user.

Then, I went to the Server Explorer, navigated to the table UserProfile, right-clicked the table and clicked New Query

And executed this query

insert into dbo.UserProfile (UserId,UserName) 
values ("test", "test")

This results in

Msg 207, Level 16, State 1, Line 1
Invalid column name 'test'.
Msg 207, Level 16, State 1, Line 1
Invalid column name 'test'.

Note: I also executed Enable-Migrations using Package Manager Console but the error message still comes.

Any ideas why ?

Update 1:

According to @CodeCaster's answer, I executed with ['] single quotes and it seems to be working fine.

However, now I get

Cannot insert explicit value for identity column in table 'UserProfile' when IDENTITY_INSERT is set to OFF

marc_s
  • 675,133
  • 158
  • 1,253
  • 1,388

2 Answers2

4

Use single quotes in SQL... ('test', 'test')

CodeCaster
  • 131,656
  • 19
  • 190
  • 236
2

Try this code

insert into dbo.UserProfile (UserId,UserName) values ('test','test')

you are using " instead of ' change "test" to 'test'

Single quotes are used to indicate the beginning and end of a string in SQL. Double quotes generally not using in SQL

Arun Chandran C
  • 3,306
  • 7
  • 28
  • 44