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
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