i am inserting 5 different things including passport to sql dbs. to my surprised, other items were inserted but the passport cell; what i see was --'binary data'. and the exception says OBJECT CANNOT BE CAST FROM DBNULL TO OTHER TYPES. pls some one should help me out here.

This is a common error that you get when trying to display a field with no value (null), from a table. If for example you have a field where you store the age of the employee, but you don't know the age of all employees, and thus those fields are set to NULL. Trying to retrieve this in your C# application and convert it to a string or another data type will result in this "cannot cast from DBNull" error. To prevent this simply check if the value is DBNull:

if(myDataReader["EmployeeAge"] != System.DBNull.Value)
{
//Code goes here
}

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.