retrieving image from an access database, need help, greatly!

  • From: prateek aggarwal <prateekagarwal99@xxxxxxxxx>
  • To: programmingblind <programmingblind@xxxxxxxxxxxxx>
  • Date: Wed, 14 Apr 2010 22:38:07 +0530

Hey list, I’m in a dilemma,
and even after trying so much, I’m not able to bypass it.
I’ll be extremely grateful if you can solve this problem of mine:
I want to retrieve an image from Access Database in which fields are defined as
        coloumn Name = Photo
        dataType = memo
here memo takes large data upto 2 or 3 Gb, but it treats whole data as
part of the string.
that's why the image store in it is of string type.
Unfortunately, I could not find how to retrieve
                                            the image from an access
database therefore.
here’s the code that I’m using:

                                                             //For
Inserting Image
  private int updateImage()
        {
            int j = 0;
            string strBLOBFilePath = ImagePath;
            int id = Convert.ToInt32(EmployeeId.ToString());
            string qryPhoto = "Update  Emp_PersonalDetails SET photo =
@BLOBData Where ID = " + id + "";
            OleDbCommand cmd = new OleDbCommand(qryPhoto, con);
            FileStream fsBLOBFile = new FileStream(strBLOBFilePath,
FileMode.Open, FileAccess.Read);
            Byte[] bytBLOBData = new Byte[fsBLOBFile.Length];
            fsBLOBFile.Read(bytBLOBData, 0, bytBLOBData.Length);
            fsBLOBFile.Close();
            OleDbParameter prm = new OleDbParameter("@BLOBData",
OleDbType.VarBinary, bytBLOBData.Length, ParameterDirection.Input,
false, 0, 0, null,
DataRowVersion.Current, bytBLOBData);
            cmd.Parameters.Add(prm);


            j = cmd.ExecuteNonQuery();
            return j;
        }
// it is working successfully
and show value like "?????Aa??";

// Now for retrieving that image
  private void displayImage()
        {


            try
            {
                Image cuurImage;
                int id = Convert.ToInt32(EmployeeId);
                OleDbCommand cmd = new OleDbCommand("Select Photo from
Emp_PersonalDetails where ID = " + id + " ", con);
                OleDbDataAdapter da = new OleDbDataAdapter(cmd);
                DataSet ds = new DataSet();
                da.Fill(ds, "tbl_student");
                int c = ds.Tables["tbl_student"].Rows.Count;

                if (c > 0)
                {
                    Byte[] data = new Byte[0];
                    string temp = "";

                    temp = ds.Tables[0].Rows[0][0].ToString();

                    System.Text.Encoding enc = System.Text.Encoding.ASCII;
                   data = enc.GetBytes(temp);

                   MemoryStream strm = new MemoryStream() ;

                   strm.Write(data, 0, data.Length);
                   strm.Position = 0;


                   pictureBox1.Image  = System.Drawing.Image.FromStream(strm);





                    }
                }

            catch (Exception ex) { }

        }

But it is giving Error That parameter is not valid . I’ve done all
sorts of my brain boggling,  searched many websites, but all  they are
showing similar codes for this purpose.
Even i also used serialization, but  the error that it gives is
something like “can't able to read stream during deserialization.”

I’m wondering what the problem is,  it seems pretty general but I’m
not able to solve it at the moment.
So, I’m in great need, please, help me finding a solution and how so
ever, just  assist me, how can I retrieve the image from an access
database which I’ve already stored successfully.

Please, folks, drop me a response if you know how to solve the same,
I’m in great need to do it, yet I’m not able to find any working
solution till now.

In wait of your response,
Prateek agarwal.

Hey list, I’m in a dilemma,
and even after trying so much, I’m not able to bypass it.
I’ll be extremely grateful if you can solve this problem of mine:
I want to retrieve an image from Access Database in which fields are defined as
        coloumn Name = Photo
        dataType = memo
here memo takes large data upto 2 or 3 Gb, but it treats whole data as
part of the string.
that's why the image store in it is of string type.
Unfortunately, I could not find how to retrieve
                                            the image from an access
database therefore.
here’s the code that I’m using:

                                                             //For
Inserting Image
  private int updateImage()
        {
            int j = 0;
            string strBLOBFilePath = ImagePath;
            int id = Convert.ToInt32(EmployeeId.ToString());
            string qryPhoto = "Update  Emp_PersonalDetails SET photo =
@BLOBData Where ID = " + id + "";
            OleDbCommand cmd = new OleDbCommand(qryPhoto, con);
            FileStream fsBLOBFile = new FileStream(strBLOBFilePath,
FileMode.Open, FileAccess.Read);
            Byte[] bytBLOBData = new Byte[fsBLOBFile.Length];
            fsBLOBFile.Read(bytBLOBData, 0, bytBLOBData.Length);
            fsBLOBFile.Close();
            OleDbParameter prm = new OleDbParameter("@BLOBData",
OleDbType.VarBinary, bytBLOBData.Length, ParameterDirection.Input,
false, 0, 0, null,
DataRowVersion.Current, bytBLOBData);
            cmd.Parameters.Add(prm);


            j = cmd.ExecuteNonQuery();
            return j;
        }
// it is working successfully
and show value like "?????Aa??";

// Now for retrieving that image
  private void displayImage()
        {


            try
            {
                Image cuurImage;
                int id = Convert.ToInt32(EmployeeId);
                OleDbCommand cmd = new OleDbCommand("Select Photo from
Emp_PersonalDetails where ID = " + id + " ", con);
                OleDbDataAdapter da = new OleDbDataAdapter(cmd);
                DataSet ds = new DataSet();
                da.Fill(ds, "tbl_student");
                int c = ds.Tables["tbl_student"].Rows.Count;

                if (c > 0)
                {
                    Byte[] data = new Byte[0];
                    string temp = "";

                    temp = ds.Tables[0].Rows[0][0].ToString();

                    System.Text.Encoding enc = System.Text.Encoding.ASCII;
                   data = enc.GetBytes(temp);

                   MemoryStream strm = new MemoryStream() ;

                   strm.Write(data, 0, data.Length);
                   strm.Position = 0;


                   pictureBox1.Image  = System.Drawing.Image.FromStream(strm);





                    }
                }

            catch (Exception ex) { }

        }

But it is giving Error That parameter is not valid . I’ve done all
sorts of my brain boggling,  searched many websites, but all  they are
showing similar codes for this purpose.
Even i also used serialization, but  the error that it gives is
something like “can't able to read stream during deserialization.”

I’m wondering what the problem is,  it seems pretty general but I’m
not able to solve it at the moment.
So, I’m in great need, please, help me finding a solution and how so
ever, just  assist me, how can I retrieve the image from an access
database which I’ve already stored successfully.

Please, folks, drop me a response if you know how to solve the same,
I’m in great need to do it, yet I’m not able to find any working
solution till now.

In wait of your response,
Prateek agarwal.
__________
View the list's information and change your settings at
//www.freelists.org/list/programmingblind

Other related posts:

  • » retrieving image from an access database, need help, greatly! - prateek aggarwal