Problem writing a simple SELECT query [closed]
string insertCommand = "INSERT INTO Users (UserID) VALUES ('"+UsersIdentityToinsert+"')"; //Exception: Cannot insert the value NULL into column 'Reputation', table 'model.dbo.Users'; column does not allow nulls. INSERT fails.
The statement has been terminated.
When i execute this command with sqlCommand.ExecuteNonQuery();. it sa开发者_高级运维ys i cant put nulls in to the column. But in the debugging, i saw that UsersIdentityToinsert has a Guid value
Why is reader null?
It shouldn't be. It may have .HasRows == false, but there should be an object.
Why do you think it ever is null?
OK, new title with a clue.
You have to drop the @
in the SQL text as it denotes @UserID as a parameter and not as a column. And I'm also doubtful about the SELECT part. Try:
"SELECT UserID FROM Users WHERE UserID= '" + UsersIDentity + "'"
精彩评论