开发者

Problem writing a simple SELECT query [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.
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 + "'"
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜