c# - SqlDataReader - how to discover that column is empty -


I try to read the result of the query and find out that some columns are empty This is the way I started Is:

  SqlDataReader rdr = cmd.ExecuteReader (); While (rdr.Read ()) {rdr ["ColumnName"]; // How do I know if its value is empty}   

I thought:

  dr [4]. Ostring () == string . Empty   

This does a necessary job, but I do not like it (this is a hack instead of solution) Can you advise me how to do it properly and beautifully Should i

is not present for the empty properties and what is right when working with the database Null which is the only true "empty"

  SqlDataReader rdr = cmd.ExecuteReader (); Int colInndex = read.GetOrdinal ("MyColumnName"); While (rdr.Read ()) {// true | False] your verification goes here ;; If (rdr.IsDBNull (colIndex)) {// value is null}}   

Please note that if you specify 0, "" or 1/1/1900 as empty value A custom treatment is required if you want to use it.

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -