blob and datagrid

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
 
I

Ignacio Machin \( .NET/ C# MVP \)

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();
}
 
G

Guest

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
 
I

Ignacio Machin \( .NET/ C# MVP \)

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top