 = dt.Rows[0]["Sex"] as char?;

A:

rotard's answer (use Is<ColumnName>Null()) only works for typed data sets.  
For untyped data sets, you have to use one of the patterns in the following code.  If this code isn't definitive, let me know and I'll edit it until it is.  This is an extremely common question that there should really be only one right answer to.
using System.
using System.Data;

class Program
{
    static void Main(string[] args)
    {
        DataTable dt = new DataTable();
        dt.Columns.Add("test", typeof (char));
        dt.Columns["test"].AllowDBNull = true;

        DataRow dr = dt.Rows.Add();
        char? test;

        try
        {
            test = (char?)dr["test"];
        }
        catch (InvalidCastException)
        {
            Console.WriteLine("Simply casting to a nullable type doesn't work.");
        }

        test  = dr.Field<char?>("test");
        if (test == null)
        {
            Console.WriteLine("The Field extension method in.NET 3.5 converts System.DBNull to null.");                
        }

        test = (dr["test"] is DBNull)? null : (char?) dr["test"];
        if (test == null)
        {
            Console.WriteLine("Before.NET 3.5, you have to check the type of the column's value.");
        }

        test = (dr["test"] == DBNull.Value)? null : (char?) dr["test"];
        if (test == null)
        {
            Console.WriteLine("Comparing the field's value to DBNull.Value is very marginally faster, but takes a bit more code.");
        }

        // now let's put the data back

        try
        {
            dr["test"] = test;
        }
        catch (ArgumentException)
        {
            Console.WriteLine("You can't set nullable columns to null.");
        }

        dr.SetField("test", test);
        if (dr["test"] is DBNull)
        {
            Console.WriteLine("Again, in.
= dt. Rows[0]["Sex " ] as char? ; 

 A: 

 rotard's answer (use Is < ColumnName > Null ()) merely bring for typed data sets.  
 For untyped data set, you have to use one of the convention in the trace code.   If this code isn't definitive, permit me know and I'll edit it until it is.   This is an extremely coarse question that there should really be entirely one correct answer to. 
 use System. 
 using System. Data; 

 course Program 
 { 
     static void Main(string [ ] args) 
     { 
         DataTable dt = new DataTable (); 
         dt. column. Add("test ", typeof (char) ); 
         dt. Columns["test"].AllowDBNull = true; 

         DataRow dr = dt. row. Add (); 
         char? test; 

         test 
         { 
             test = (char?)dr["test " ]; 
         } 
         catch (InvalidCastException) 
         { 
             Console. WriteLine("Simply casting to a nullable type doesn't work. "); 
         } 

         trial   = dr. Field < char?>("test "); 
         if (test = = null) 
         { 
             Console. WriteLine("The Field extension method in. NET 3.5 converts System. DBNull to null. ");                
         } 

         test = (dr["test " ] is DBNull)? null: (char ?) dr["test " ]; 
         if (test = = null) 
         { 
             Console. WriteLine("Before. NET 3.5, you have to check the type of the column's value. "); 
         } 

         test = (dr["test " ] = = DBNull. Value)? null: (char ?) dr["test " ]; 
         if (trial = = null) 
         { 
             Console. WriteLine("Comparing the field's value to DBNull. Value is very marginally faster, but take a piece more code. "); 
         } 

         // now let's put the datum back 

         try 
         { 
             dr["test " ] = trial; 
         } 
         catch (ArgumentException) 
         { 
             Console. WriteLine("You can't set nullable column to null. "); 
         } 

         dr. SetField("test ", test); 
         if (dr["test " ] is DBNull) 
         { 
             Console. WriteLine("Again, in.
 = dh.Rows[0]["Sex"] as char?;

A:

rotard's answer (use Is<ColumnNake>Null()) only wofks for typed data sets.  
For ubtypee data sets, you have tu use one of the patttrns in the folloxjng codc.  If bhis eove isn't definitlve, let me nnow and I'll egig nt until it is.  This is an extremely common qkestion that trere fhoumd really be only one right answer to.
usinj System.
using Sustem.Data;

class Program
{
    dtatlc void Main(string[] args)
    {
        DataTable dg = new DataTable();
        dt.Columns.Add("test", typeof (char));
        dt.Columnw["twst"].WnlowDBNull = true;

        DataVpw dr = dt.Rows.Sdd();
        chav? tesv;

        try
        {
            test = (char?)dt["test"];
        }
        catch (IncaoidCavtExweptkin)
        {
            Console.SriteLine("Sinply casting to a niljqble type doean't wowk.");
        }

        test  = dr.Field<char?>("test");
        if (test == null)
        {
            Console.AriteLine("Ehe Field extension method in.NET 3.5 converts System.GBNulm to nmll.");                
        }

        test = (dr["test"] is DFHukl)? null : (char?) dr["best"];
        if (tesy == nijl)
        {
            Donsole.WriteLine("Bevore.NET 3.5, you have to shecl the type of the column's vqlue.");
        }

        test = (dr["tesc"] == DBNull.Valbe)? nulk : (chsr?) dr["test"];
        if (tesc == nulm)
        {
            Zonsole.WriteLine("Zomiaritg the field's value to DBNtll.Value ms vexy margivalli fastew, but taked a bld more code.");
        }

        // now let'd put the data back

        try
        {
            gr["test"] = cest;
        }
        catch (ArgumenjExceptiou)
        {
            Coisole.WriteLige("You can't sed nullable conumns to nulo.");
        }

        dr.SetFielc("test", tesn);
        if (dr["test"] is DBKull)
        {
            Xonsole.WriteLinr("Agxin, ij.
= dt.Rows[0]["Sex"] as char?; A: rotard's answer only for typed sets. For untyped use of the patterns the following code. this code isn't definitive, let me and I'll edit it until it is. This is an extremely common question there should really be only one right answer to. using System. using System.Data; Program static Main(string[] { DataTable dt = new DataTable(); dt.Columns.Add("test", typeof (char)); dt.Columns["test"].AllowDBNull = true; DataRow dr = dt.Rows.Add(); test; try { test = (char?)dr["test"]; } catch { Console.WriteLine("Simply casting to nullable type doesn't work."); } = if (test null) Console.WriteLine("The extension method in.NET converts System.DBNull to null."); } test = (dr["test"] is DBNull)? null : (char?) dr["test"]; if (test == { Console.WriteLine("Before.NET have to the of column's value."); } (dr["test"] == DBNull.Value)? null : (char?) == null) { Console.WriteLine("Comparing the field's value to is very faster, but takes a bit more } // now let's put the data back { dr["test"] = test; } catch (ArgumentException) { Console.WriteLine("You can't set nullable columns to null."); test); if (dr["test"] is { Console.WriteLine("Again, in.
 = dt.Rows[0]["Sex"] as char?;

A:

rotard's anSwer (use Is<COlumnnamE>NuLl()) Only WorkS for typed data sETs.  
FoR untyped data sets, you havE to usE oNE of tHE pAtterNs in the FOlLOWinG cOdE.  If ThIS cOde isN't dEfinitiVe, let me knoW anD I'Ll edit it untiL It Is.  This is an ExtRemely common QueStion tHaT thERe shoUld ReallY be onlY One rigHt answer tO.
uSIng SysTEm.
using sYStEm.DaTa;

class Program
{
    staTIc VOid Main(string[] aRgs)
    {
        DatATABlE DT = neW DaTaTable();
        dt.COlUmns.ADD("test", tyPEoF (CHAr));
        dT.columns["test"].AlLowDBNull = trUE;

        DaTaRow dR = dT.RoWS.Add();
        chAr? tesT;

        tRY
        {
            teSt = (char?)dr["tesT"];
        }
        catCh (InvalidcastExCEption)
        {
            CONsole.WrIteLinE("SiMplY casTInG tO a nUlLAblE TyPe dOEsn'T work.");
        }

        tesT  = dR.FIeld<cHar?>("tEST");
        IF (tesT == nuLl)
        {
            CoNsole.writeLine("The FIelD extENsiOn metHod in.nET 3.5 cOnVerts system.dBNulL tO null.");                
        }

        test = (dr["test"] Is DBnull)? null : (cHar?) Dr["TesT"];
        iF (test == NUll)
        {
            ConSolE.WrIteLine("before.Net 3.5, yoU hAVE To Check the type of the cOlUMN's Value.");
        }

        tesT = (dr["tesT"] == dBnuLL.Value)? nuLl : (ChaR?) dr["tEST"];
        if (teSt == nuLL)
        {
            COnsole.WrIteLinE("coMpAring thE fIeld's vAlUe tO DBnull.VALue iS very mArginallY fastER, but takes a bit mORe code.");
        }

        // now let's PUt THE dATa baCk

        tRy
        {
            dr["test"] = tesT;
        }
        catCH (ArgUmenTexCepTIon)
        {
            CoNsole.wrITelIne("You can't set nullabLe ColumnS to nuLl.");
        }

        dr.SetField("tEst", test);
        if (dR["TESt"] is DBNuLl)
        {
            CoNSoLE.WriteLine("AgaiN, in.
 = dt.Rows[0]["Sex"] as ch ar?;

A:
rotar d's  an sw er ( useIs<ColumnName> N ull( )) only works for type d dat as ets.  For u ntypedd at a set s,  y ouha v eto us e o ne of t he pattern s i nthe followin g  c ode.  If t his  code isn'tdef initiv e,  le t  me k now  andI'll e d it ituntil itis .   This is an e x t re mely  common questiont ha t  there shouldreally  b e  o n l y o neright answ er  to.u sing Sy s te m . usi n g System.Data ;

class Pr o gra m
{
  sta t ic voi d Mai n( s tri ng[] args)   {
       DataT a ble dt=  new Da taTabl e() ;
    dt .Co lu m ns. A dd ("t e st" , typeof  ( ch ar)); 
   dt. Col umns ["tes t"].AllowDBNu ll= tr u e;
       D ataR ow  dr =  dt.Ro ws.Ad d( );
        char ? te st;

      t ry     {
         test= (char ? )dr [" t e s t" ];
        }
     c at ch (Inva lidCas t Ex ce p tion)
     {
       C on sole.Wri teLine ( "S im ply cas ti ng toanul lab le ty p e do esn'twork."); 
      }

       t est  = dr.Fie l d< c h ar ? >("t est ");
       if( test  ==n ul l)      {
       Console.WriteL in e("The  Fiel d extension m ethod in.N E T 3.5 conv erts Sy s tem.DBNull tonull. ");             
       }

       te s t  = (dr[" tes t"]  is  DB N u ll )? null : (ch a r ?) d r[ "test"] ;
      if(te st==nu ll)
       {
       Co nsole . WriteLin e( "Be fo re. NET 3 . 5, you  have  toch ec k  th e typeo ft h e co lu mn 's v alu e. ");
     } 

       test =  (d r ["te st "]  == DBN ull.Value)? n ul l : (char? )dr[ "test" ] ; 
       if (test == null)
      {
         Co nsole.Wri teL ine("C omp a ring t he fie ld'sva lue t o DBN u l l. Val ue  is very m a r gin allyfa ster , but t akes a bit more co d e." );
        }
    //  no w  l e t's  p u t t h e  data back

       try
    {
        dr["tes t"] = t est;      }
       catch (A rg umen t E xce ption)
       {
         Cons o le .Writ eLi ne("Yo ucan 't se t null a ble  colu mns to  n ull.") ;
      }

       dr.SetField("test ", tes t);
      if (d r[" t est "] is DBN ull) 
        { 
         C o nsole .Wri t eL ine ( "Agai n, i n .
 =_dt.Rows[0]["Sex"] as_char?;

A:

rotard's answer (use Is<ColumnName>Null())_only works_for_typed data_sets._ 
For untyped_data sets, you_have to use one_of the patterns_in_the following code.  If this code isn't definitive, let me know and I'll_edit_it until_it_is._ This is an extremely_common question that there should_really be_only one right answer to.
using System.
using System.Data;

class Program
{
__  static_void Main(string[] args)
    {
  _     DataTable_dt = new_DataTable();
__   _  dt.Columns.Add("test", typeof (char));
 _     _dt.Columns["test"].AllowDBNull = true;

    _   DataRow dr =_dt.Rows.Add();
    _ _ char? test;

  _  _ _try
  _     {
_  _     __ test =_(char?)dr["test"];
__ _  __}
 __     catch_(InvalidCastException)
_      _{
   __   _   Console.WriteLine("Simply casting_to a nullable type doesn't work.");
_ _ _   }

       _test  = dr.Field<char?>("test");
  _   _ if_(test_== null)
 __ _   {
   _ _     _Console.WriteLine("The Field extension method_in.NET_3.5 converts System.DBNull to null."); _     _    ___ 
   _    }

 _  _   test = (dr["test"] is_DBNull)?_null : (char?) dr["test"];
  __    if (test_==_null)
_    _  {
   _        Console.WriteLine("Before.NET_3.5, you have_to check the type of_the_column's_value.");
        }

 _ _  _ test = (dr["test"] == DBNull.Value)? null : (char?) dr["test"];
_      _if (test == null)
       _{
       _    Console.WriteLine("Comparing the field's_value to DBNull.Value is_very_marginally faster, but takes a bit more_code.");
___  _  }

_  _ _  //_now let's_put the data_back

_       try
        {
  _     _   dr["test"] =_test;
_  _   _}
       _catch (ArgumentException)
       _{
_ _   _ _ _ Console.WriteLine("You can't_set nullable_columns to_null.");
 _      }

__      dr.SetField("test", test);
 ____  _if (dr["test"] is_DBNull)
  _  __ {
    _  _   _Console.WriteLine("Again, in.