Handling Null in C# win application

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • andyehi
    New Member
    • Nov 2008
    • 20

    Handling Null in C# win application

    Hi
    My application will select and read records using datareader from mysql table and do insert or update on access data base.My problem is when I set the mdb database to allow zero length string the code below works fine.But if it is set to no.I get this error.I want to however insert a null in Access database.Any help would be great! Thanks

    // Field 'patientinfo.Pa tient Last' cannot be a zero-length string. //

    Code:
     
    
     string firstname1 = myreader["firstname"].ToString();
    
      string lastname1 = myreader["lastname"].ToString();
    
      string CI_address11 = myreader["CI_address1"].ToString();
    
      string CI_address21 = myreader["CI_address2"].ToString();
    
    // insert query 
    
     OdbcCommand mycommand4 = new OdbcCommand("insert into patientinfo([patientid],[patient first],[patient last],[pt DOB],[SSN],[address],[address2],[city],[state],[zipcode],[sex]) values ('" + MRN1 + "','" + firstname1 + "','" + lastname1 + "','" + dob1 + "','" + ssn1 + "','" + CI_address11 + "','" + CI_address21 + "','" + CI_city1 + "','" + CI_state1 + "','" + CI_zip1 + "','" + sex1 + "')", mdbconn);
      
     int k = mycommand4.ExecuteNonQuery();
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    Take a look at DBNull.Value

    Comment

    • andyehi
      New Member
      • Nov 2008
      • 20

      #3
      Thank you ,will try it.

      Comment

      Working...