Link to home
Start Free TrialLog in
Avatar of Abhilash Nagar
Abhilash Nagar

asked on

System.Data.SqlTypes.SqlNullValueException: Data is Null.This method or property cannot be called on Null values.

Hello,
I am getting below error :
 
System.Data.SqlTypes.SqlNullValueException: Data is Null. This method or property cannot be called on Null values.
   at System.Data.SqlClient.SqlBuffer.get_Int64()
   at System.Data.SqlClient.SqlDataReader.GetInt64(Int32 i)

Open in new window


This comes on line row[7] where it is assigning Date value. This is assigning to DataRow in Datatable , Please help.Thanks I checked there are data available in reader there is nothing like NULL for data. There is data present.


                    while (dr.Read() == true)
                    {
                        
                        if (Uid!= dr.GetInt32(0))
                        {

                            row = table.NewRow();
                            rectificationId = dr.GetInt32(0);
                            row[0] = dr.GetInt32(14);
                            row[1] = IdTest; 
                            row[2] = dr.GetString(1); 
                            row[3] = dr.GetInt32(2); 
                            row[4] = dr.IsDBNull(4) ? 0 : dr.GetInt32(4);                           
                            row[5] = dr.IsDBNull(6) ? string.Empty : dr.GetString(6); 
                            row[6] = dr.GetString(11); 
                         [b]   row[7] = new DateTime(dr.GetInt64(12)); [/b]
                            row[8] = new DateTime(dr.GetInt64(8)); 
                            row[9] = new DateTime(dr.GetInt64(9)); 
                            row[10] = dr.GetString(7); 
                            row[11] = dr.GetInt32(5); 
                            row[12] = dr.GetString(10); 
                            if (dr.IsDBNull(15))
                                row[14] = DBNull.Value;
                            else
                                row[14] = new DateTime(dr.GetInt64(15)); 


                          

}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Pratik Somaiya
Pratik Somaiya
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Abhilash Nagar
Abhilash Nagar

ASKER

Thanks Pratik that helped. There was null coming from Date field.
Thanks Pratik that helped. There was null coming from Date field.
That's great to know it helped.