Christiaan Baes Belgium My Blog "In a system where you can define a factor as part of a third factor, you need another layer to check the main layer in case the second layer is not the base unit. Now you can go where they get things done! Thank you for helping keep Tek-Tips Forums free from inappropriate posts. The Tek-Tips staff will check this out and take appropriate action. Click Here to join Tek-Tips and talk with other members!
Already a Member? Join your peers on the Internet's largest technical computer professional community. It's easy to join and it's free. Register now while it's still free! Already a member? Close this window and log in. Join Us Close. Join Tek-Tips Forums! Join Us! By joining you are opting in to receive e-mail. Promoting, selling, recruiting, coursework and thesis posting is forbidden. It has to be the value of the object -- which it cannot be until I cast it.
I can check the object as to whether or not it is null. So my thinking is, well, ExecuteScalar only returns one row, one column anyway a single value or else it returns null. Is that the wrong way of looking at it? Earl wrote: Hmmm, I can't check DbNull. The following primitive examples works for me: using System; using System. This discussion thread is closed Start new discussion.
Dealing with a null BLOB field. How to detect NULL value with cmd. ExecuteScalar ;. Visual Basic. Microsoft SQL Server. 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. It isn't a Guid. The Value of a SqlParam is a basic Object. I doubt the as operator specifically inspects SqlParams to check what DbType they are.
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. Ah OK. I see what you're saying now. Use reader. HasRows to check if the query returns a result or not. Next, you cannot ask the reader for the position of the "ID" column, since your query does not contain a column with that name.
Posted Jan am Bernhard Hiller. Linux Goblin Jan am. Hi, I've just tried what you've said and changed the code up a bit, I now get the following error: "An unhandled exception of type 'System. ArgumentException' occurred in MySql. Change your code to this: C. Posted Jan am Ron Beyer. After using the break points, it gets to the IF statement then jumps straight to the else.
I have a feeling it is partially due to the SQL query but then again if nothing is in the table then scalarVal should be NULL and then do something else. So what is the value that is actually being returned from ExecuteScalar?
The value of scalarVal in my suggestion? This will help narrow it down To see what is really returned? Checked what you mentioned, if there is a value in the table it is successfully pulling the value found what is causing the program to crash HOWEVER when there is no value in the table scalarVar does return blank but it still registers as a value so it is jumping to the ELSE statement maybe because it isn't DBNull?
If you put a watch or mouse hover over scalarVal what is its type? If its not null it should be something like an integer, there really isn't a "blank" type With no values in the table it is returning as "Object".
Try replacing if cs.
0コメント