Networks

Our forums are currently in maintenance mode and the ability to post is disabled. We will be back up and running as soon as possible. Thanks for your patience!

Question

Locked

How could i resolve "Invalid Parameter Used" error?

By sahernaqi ·
I m trying to display jpg image on C# web page retrieved from ms-access database. Image is stored in database as OLE object under img_stream" variable. My code is:
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
myAccessConnection = new OleDbConnection(connStr);
openAccessConnection();
OleDbCommand myCommand = new OleDbCommand("select img_stream from tblImg where img_id=4", myAccessConnection);
//myCommand.CommandType = CommandType.Text;
//OleDbParameter img_id = new OleDbParameter("4", OleDbType.Integer);
//myCommand.Parameters.Add(img_id);
OleDbDataAdapter myAdapter = new OleDbDataAdapter(myCommand);
DataSet myDataSet = new DataSet();
myAdapter.Fill(myDataSet);
MemoryStream ms = new MemoryStream();
DataTable dataTable;
dataTable = myDataSet.Tables["tblImg"];
OleDbDataReader reader = myCommand.ExecuteReader();
if(reader.Read())
{
//System.Drawing.Image _image = System.Drawing.Image.FromStream( new System.IO.MemoryStream( (byte[])reader["img_stream"] ) );


Response.ContentType = "image/jpeg";
byte[] imageContent = (byte[])(reader["img_stream"]);
ms.Write(imageContent, 0, imageContent.Length);
Bitmap bmp;
bmp = new Bitmap(ms);
bmp.Save(Response.OutputStream, ImageFormat.Jpeg);
ms.Close();
closeAccessConnection();
}
else
{
closeAccessConnection();
}
}
String connStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + HttpContext.Current.Server.MapPath("App_Data/db1.mdb");

// Object created for Oledb Connection
OleDbConnection myAccessConnection;

protected void openAccessConnection()
{
// If condition that can be used to check the access database connection
// whether it is already open or not.
if (myAccessConnection.State == ConnectionState.Closed)
{
myAccessConnection.Open();
}
}

protected void closeAccessConnection()
{
// If condition to check the access database connection state
// If it is open then close it.
if (myAccessConnection.State == ConnectionState.Open)
{
myAccessConnection.Close();
}

}
I get the following error on executing this code: "Invalid Parameter Used" on line "bmp = new Bitmap(ms)"
Please i need help to resolve this error...as it has been so long i m trying to get rid of it...

This conversation is currently closed to new comments.

Thread display: Collapse - | Expand +

All Answers

Share your knowledge

Related Discussions

Related Forums