Can anyone explain why this doesn’t work:
command.CommandText = "SELECT [Token] FROM Clients WHERE
[Token] ='" + client1.Token + "'";
Guid result = new Guid(command.ExecuteScalar() as string);
While this does work:
command.CommandText = "SELECT [Token] FROM Clients WHERE
[Token] ='" + client1.Token + "'";
Guid result = new Guid(command.ExecuteScalar().ToString());
The first snippet returns null. The second returns the requested Guid. The only difference is as string and .ToString(). This seems to only happen on uniqueidentifier columns in .NET 2.0.
(And don’t wonder why the code doesn’t seem to have a purpose, it is a bit from a larger a unit test.)
Add New Comment
Viewing 7 Comments
Thanks. Your comment is awaiting approval by a moderator.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Add New Comment
Trackbacks
(Trackback URL)