Zero Check

Sorry for such a simple question.

How can I check this for zeros?

obj.DivisionNotes = (string)row["DivisionNotes"];

I think something like this.

obj.DivisionNotes = (string)row["DivisionNotes"]?null:"No notes";

I'm right.

Any help is greatly appreciated.

+3
source share
3 answers

Your null rejection will cause a problem, you can use a command aswith a null coalescing operator to solve your problems.

obj.DivisionNotes = (row["DivisionNotes"] as string) ?? "No notes";
+10
source

You can use the ISNULL function in the original T-SQL query by changing this query:

SELECT ID, Name, DivisionNotes FROM tblWHATEVER

to

SELECT ID, Name, ISNULL(DivisionNotes, 'No notes') AS 
    DivisionNotes FROM tblWHATEVER

I'm not saying that this is better than checking for zero in the code, but sometimes a simple change in the request can save you from changing the code in a bunch of different places.

+1
source

datarow. , , .

+1

Source: https://habr.com/ru/post/1718859/


All Articles