blob and datagrid

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

All,

I have a blob image (jpeg) in a sql server table and would like to display
it within my datagrid on my ASP.Net C# web form is this possible and how?

Thanks
Msuk
 
Hi,

You have to extract it, save it to disk and then serve it, the code below
does that, please note that they are pieces of code, so it will not work as
is

It's just to give you an idea

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation



protected override void Load()
{
saved = true;

//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"]);
//Now we have to save the image

this.name = Guid.NewGuid().ToString() + "." + origname.Substring(
origname.LastIndexOf(".")+1);
physicalname = physicalname + @"\" + name;
ExtracFileFromDB( reader);

}
reader.Close();
}
protected void ExtracFileFromDB( SqlDataReader reader)
{
FileStream file = new FileStream( physicalname, FileMode.Create);
file.Write( (byte[])reader["Data"], 0,
((byte[])reader["Data"]).GetUpperBound(0)+1 );
file.Close();
}
 
Hi,

Once I have wrttien the file to disk how will I display it in the datagrid?

Thanks
Msuk

Ignacio Machin ( .NET/ C# MVP ) said:
Hi,

You have to extract it, save it to disk and then serve it, the code below
does that, please note that they are pieces of code, so it will not work as
is

It's just to give you an idea

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation



protected override void Load()
{
saved = true;

//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"]);
//Now we have to save the image

this.name = Guid.NewGuid().ToString() + "." + origname.Substring(
origname.LastIndexOf(".")+1);
physicalname = physicalname + @"\" + name;
ExtracFileFromDB( reader);

}
reader.Close();
}
protected void ExtracFileFromDB( SqlDataReader reader)
{
FileStream file = new FileStream( physicalname, FileMode.Create);
file.Write( (byte[])reader["Data"], 0,
((byte[])reader["Data"]).GetUpperBound(0)+1 );
file.Close();
}


msuk said:
All,

I have a blob image (jpeg) in a sql server table and would like to display
it within my datagrid on my ASP.Net C# web form is this possible and how?

Thanks
Msuk
 
Hi,

You just include an image and the src will be the generated named. this mean
you needs to keep track of the generated names and to what rows they refer
to.

You could do this in a number of ways, the easier one I can think of right
now is at bind time, it could be slow though.


cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation



msuk said:
Hi,

Once I have wrttien the file to disk how will I display it in the
datagrid?

Thanks
Msuk

Ignacio Machin ( .NET/ C# MVP ) said:
Hi,

You have to extract it, save it to disk and then serve it, the code below
does that, please note that they are pieces of code, so it will not work
as
is

It's just to give you an idea

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation



protected override void Load()
{
saved = true;

//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"]);
//Now we have to save the image

this.name = Guid.NewGuid().ToString() + "." + origname.Substring(
origname.LastIndexOf(".")+1);
physicalname = physicalname + @"\" + name;
ExtracFileFromDB( reader);

}
reader.Close();
}
protected void ExtracFileFromDB( SqlDataReader reader)
{
FileStream file = new FileStream( physicalname, FileMode.Create);
file.Write( (byte[])reader["Data"], 0,
((byte[])reader["Data"]).GetUpperBound(0)+1 );
file.Close();
}


msuk said:
All,

I have a blob image (jpeg) in a sql server table and would like to
display
it within my datagrid on my ASP.Net C# web form is this possible and
how?

Thanks
Msuk
 
Back
Top