get a picture field in oracle and display in asp.net

G

Guest

I use the following code for getting a picture from oracle:
OraCon.Open();


// define the sql to perform the database insert
string sqlStmt = "select foto from ov_portal_foto";

// Establish a new OracleCommand
OracleCommand cmd = new OracleCommand();
// Set command to create your SQL statement
cmd.CommandText = sqlStmt;
// Set the OracleCommand to your database connection
cmd.Connection = OraCon;
// Set the command type to text
cmd.CommandType = CommandType.Text;
// Execute the SQL Statement
OracleDataReader oraReader = cmd.ExecuteReader();
if ( oraReader.Read())
{
Response.BinaryWrite( (byte[]) oraReader["foto"] );
}

//ImageDataGrid.DataSource = oraReader;
//ImageDataGrid.DataBind();
}
catch(OracleException ex)
{
Label1.Text = ex.Message;
Label1.Visible = true;


Now when I run the code i see the following error:

Specified cast is not valid.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information about
the error and where it originated in the code.

Exception Details: System.InvalidCastException: Specified cast is not valid.

Source Error:


Line 47: if ( oraReader.Read())
Line 48: {
Line 49: Response.BinaryWrite( (byte[]) oraReader["foto"] );
Line 50: }
Line 51:

What am I doing wrong?

thanks in advance



Alles uitvouwenAlles samenvouwen
 

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

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,054
Latest member
LucyCarper

Latest Threads

Top