Question
Thread display: Collapse - |
All Answers
Share your knowledge
Start or search
Create a new discussion
If you're asking for technical help, please be sure to include all your system info, including operating system, model number, and any other specifics related to the problem. Also please exercise your best judgment when posting in the forums--revealing personal information such as your e-mail address, telephone number, and address is not recommended.
How could i resolve "Invalid Parameter Used" error?
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...