tags:

views:

60

answers:

1

Hi, i am storing an image in a table in varbinary(max) format, actually first time it will be empty,i am checking whether it is empty of not but while checking for null field i am getting any exception stating invalid cast so can any one suggest what is the problem with this.

code sample is

con = new SqlCeConnection(CommonClass.ConnectionStringStartup); con.Open();

                    SqlCeCommand cmd = con.CreateCommand();
                    cmd.CommandText = "SELECT Signature,UserId FROM UserMaster Where " +
                        " LoginName = '" + UserName + "' " +
                        " AND Password = '" + Password + "'";
                    cmd.CommandType = CommandType.Text;
                   // MessageBox.Show(UserName);

                    SqlCeDataReader dr;
                    dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);

                        if (dr.Read())
                        {

                            if (dr.IsDBNull(0))
                                SignLoaded = false;
                            else
                                SignLoaded = true;

                        }

Thanks in advance

With regards Bharath kumar

A: 

To me, it looks like this should work?

Have you tried Convert.IsDbNull( dr.GetValue(0))?

Otherwise I can only suggest using dr.GetValue(0) and look at the result.

Cheers

JJJ