Hi,
You have to check for null , if so you have to decide what to do, either
assign null to the variable or just use some predefined image.
Here is some code, it was extracted from a bigger program so it does not
compile, it's just for you to look into it
protected override void Load()
{
//generate a new local name for this file
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "LoadDocument";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@dID", SqlDbType.Int).Value = id;
SqlDataReader reader = DataProvider.ExecuteReader( cmd);
while( reader.Read() )
{
this.comment = "";
this.origname = reader["OrigName"].ToString();
this.dDate = Convert.ToDateTime( reader["dDate"]);
this.name = Guid.NewGuid().ToString() + "." + origname.Substring(
origname.LastIndexOf(".")+1);
physicalname = physicalname + @"\" + name;
ExtracFileFromDB( reader);
}
reader.Close();
}
protected void ExtracFileFromDB( SqlDataReader reader)
{
if ( reader["Data"] != DBNull.Value )
{
FileStream file = new FileStream( physicalname, FileMode.Create);
file.Write( (byte[])reader["Data"], 0,
((byte[])reader["Data"]).GetUpperBound(0)+1 );
file.Close();
}
}
cheers,
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"jack" <ga**********@gmail.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...
hi all
im facing a problem in error handelling.
what im doing is getting the images from the database to my
csharp application form .. now here in some of the records contains
images along with the data where as some as has null value ..
who to trap this please help
thanks for the help..