Community Page
- paulmwatson.com/journal Jump to website »
-
Subscribe -
Community
-
Top Commenters
-
Popular Threads
-
Recent Comments
- Make songbird look like spotify: http://addons.songbirdnest.com/addon/1440
- Got it, thanks Paul!
- Email me your email address so I can invite you Mike (paul@paulmwatson.com)
- Happy New Year to you, as well! I was stopping by to see if you would be willing to lend a reader a Spotify invitation. I am desperately hoping to be able try out the service. Thanks! Mike
- Nice one Jamie. Even more ironic is that that "mass production" is probably still underpaid, underage workers in some 3rd world country sweat-shop.
Jump to original thread »
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.Comma ... Continue reading »
command.CommandText = "SELECT [Token] FROM Clients WHERE
[Token] ='" + client1.Token + "'";
Guid result = new Guid(command.ExecuteScalar() as string);
While this does work:
command.Comma ... Continue reading »
3 years ago
When you use ToString, it will call ToString on whatever object it is that you are calling it on.
So getting different behavior is not surprising.
3 years ago
3 years ago
I tend to disagree. Though it might be "nice" for "as string" to work like "ToString" I'm much happier with consistent behaviour.
3 years ago
How can "as string" returning a null be considered consistent behaviour? It is loosing data.
3 years ago
So in your case the Guid isn't a string so it returns null. The reason I say this is consistent behaviour is that it behaves the same for any object, not just string. If you try to use the "as" operator on any type that isn't the type that you ask for then it will return null.
3 years ago
"as int" and "as string" work fine even when the SqlParam.Value is holding a bigint or a bit or a char. It just doesn't work for uniqueIdentifier which says to me there is a problem in there somewhere.
3 years ago
Although the SqlParam.Value is an Object, for a uniqueidentifier I suspect that it is actually a Guid, hence the behaviour for the as operator. That doesn't explain why "as string" works for the other types you mention, though :S
Something's not quite right somewhere along the line. Personally I'd prefer the same behaviour as uniqueidentifier for ints, etc. As long as it's consistent it doesn't really matter, but it seems that it's not :(