Some questions and pointers:
1. Instead of using if (ds.Tables[0].Rows[0][0].ToString() != "") wich will fail anyway if the value is null use the following:
if (ds.Tables[0].Rows[0][0] != DBNull.Value)
2. Next you would want to indicate what line causes the crash
3.
look here[
^] perhaps that helps you on the way.
4. don't write else statements that are emtpy, they're useless.
5. don't swallow Exceptions with empty catch statements, often done to avoid an application crash, but the very least you should log the error and inform the user.
6. "select ima from ca where carprofile='" + pid + "'" --> use parametrized queries !
Hope this helps.