Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. problem while retriving image from database. [modified]

problem while retriving image from database. [modified]

Scheduled Pinned Locked Moved C#
databasehelpcsharpandroidgraphics
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    avvaru murali
    wrote on last edited by
    #1

    Hi, iam doing windows application c# my database is "Firebird Database"; iam able to insert an picture into database,but iam unable to retrive the same.. my code is : int id = int.Parse(textBox1.Text); FbConnection cnn = new FbConnection("ServerType=1;User=SYSDBA;Password=masterkey;Database=E:/database/test.fdb"); cnn.Open(); string query = "select photo from cust1 where id=" + id; FbDataAdapter adb = new FbDataAdapter(query, cnn); DataSet ds = new DataSet(); adb.Fill(ds, "cust1"); DataRowCollection rdsrows = ds.Tables[0].Rows; if (!rdsrows[0][0].Equals(DBNull.Value)) { byte[] content = (byte[])rdsrows[0][0]; MemoryStream stream = new MemoryStream(content); Bitmap img = new Bitmap(stream);-------------------"Error Here" pictureBox1.Image = img; } it's giving error "parameter is not valid" please inform where the problem is

    murali krishna

    modified on Monday, February 25, 2008 1:36 AM

    C Z G 3 Replies Last reply
    0
    • A avvaru murali

      Hi, iam doing windows application c# my database is "Firebird Database"; iam able to insert an picture into database,but iam unable to retrive the same.. my code is : int id = int.Parse(textBox1.Text); FbConnection cnn = new FbConnection("ServerType=1;User=SYSDBA;Password=masterkey;Database=E:/database/test.fdb"); cnn.Open(); string query = "select photo from cust1 where id=" + id; FbDataAdapter adb = new FbDataAdapter(query, cnn); DataSet ds = new DataSet(); adb.Fill(ds, "cust1"); DataRowCollection rdsrows = ds.Tables[0].Rows; if (!rdsrows[0][0].Equals(DBNull.Value)) { byte[] content = (byte[])rdsrows[0][0]; MemoryStream stream = new MemoryStream(content); Bitmap img = new Bitmap(stream);-------------------"Error Here" pictureBox1.Image = img; } it's giving error "parameter is not valid" please inform where the problem is

      murali krishna

      modified on Monday, February 25, 2008 1:36 AM

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      Have you looked in the debugger to see what content looks like ? Compared it with the bytes of an image you're passing in ?

      Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

      A 1 Reply Last reply
      0
      • A avvaru murali

        Hi, iam doing windows application c# my database is "Firebird Database"; iam able to insert an picture into database,but iam unable to retrive the same.. my code is : int id = int.Parse(textBox1.Text); FbConnection cnn = new FbConnection("ServerType=1;User=SYSDBA;Password=masterkey;Database=E:/database/test.fdb"); cnn.Open(); string query = "select photo from cust1 where id=" + id; FbDataAdapter adb = new FbDataAdapter(query, cnn); DataSet ds = new DataSet(); adb.Fill(ds, "cust1"); DataRowCollection rdsrows = ds.Tables[0].Rows; if (!rdsrows[0][0].Equals(DBNull.Value)) { byte[] content = (byte[])rdsrows[0][0]; MemoryStream stream = new MemoryStream(content); Bitmap img = new Bitmap(stream);-------------------"Error Here" pictureBox1.Image = img; } it's giving error "parameter is not valid" please inform where the problem is

        murali krishna

        modified on Monday, February 25, 2008 1:36 AM

        Z Offline
        Z Offline
        zeopyrix
        wrote on last edited by
        #3

        Try using Image instead of Bitmap. Are you sure that the photo field type is BLOB (binary)? I have no idea of what happens here, but I have some experience with Firebird in C# (sourceforge.net/projects/pokelib) and I wrote some functions for image conversion: public static byte[] FileToBytes(string filePath) { FileStream fs; try { fs = new FileStream(filePath, FileMode.Open, FileAccess.Read); } catch (IOException) { return null; } // Create a byte array of file stream length byte[] fileData = new byte[fs.Length]; //Read block of bytes from stream into the byte array fs.Read(fileData, 0, System.Convert.ToInt32(fs.Length)); //Close the File Stream fs.Close(); return fileData; } public static Image FileToImage(string imagePath) { FileStream fs; try { fs = new FileStream(imagePath, FileMode.Open, FileAccess.Read); } catch (IOException) { return null; } // Create a byte array of file stream length byte[] imageData = new byte[fs.Length]; //Read block of bytes from stream into the byte array fs.Read(imageData, 0, System.Convert.ToInt32(fs.Length)); //Close the File Stream fs.Close(); MemoryStream ms = new MemoryStream(imageData); return Image.FromStream(ms); } public static byte[] ImageToBytes(Image imageIn) { MemoryStream ms = new MemoryStream(); imageIn.Save(ms, imageIn.RawFormat); return ms.ToArray(); } public static Image BytesToImage(byte[] byteArrayIn) { MemoryStream ms = new MemoryStream(byteArrayIn); Image returnImage = Image.FromStream(ms); return returnImage; }

        1 Reply Last reply
        0
        • C Christian Graus

          Have you looked in the debugger to see what content looks like ? Compared it with the bytes of an image you're passing in ?

          Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

          A Offline
          A Offline
          avvaru murali
          wrote on last edited by
          #4

          Hi, Thanks for your reply. while saving content with in bytes is showing Dimensions{77500} like this but while retriving content with in bytes showing Dimensions{13} only..

          murali krishna

          C 1 Reply Last reply
          0
          • A avvaru murali

            Hi, Thanks for your reply. while saving content with in bytes is showing Dimensions{77500} like this but while retriving content with in bytes showing Dimensions{13} only..

            murali krishna

            C Offline
            C Offline
            Christian Graus
            wrote on last edited by
            #5

            Well, gee, that seems like it could be a problem.... Sounds like your code to store the image is broken. I assume there's not more than 13 bytes in your database.

            Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

            1 Reply Last reply
            0
            • A avvaru murali

              Hi, iam doing windows application c# my database is "Firebird Database"; iam able to insert an picture into database,but iam unable to retrive the same.. my code is : int id = int.Parse(textBox1.Text); FbConnection cnn = new FbConnection("ServerType=1;User=SYSDBA;Password=masterkey;Database=E:/database/test.fdb"); cnn.Open(); string query = "select photo from cust1 where id=" + id; FbDataAdapter adb = new FbDataAdapter(query, cnn); DataSet ds = new DataSet(); adb.Fill(ds, "cust1"); DataRowCollection rdsrows = ds.Tables[0].Rows; if (!rdsrows[0][0].Equals(DBNull.Value)) { byte[] content = (byte[])rdsrows[0][0]; MemoryStream stream = new MemoryStream(content); Bitmap img = new Bitmap(stream);-------------------"Error Here" pictureBox1.Image = img; } it's giving error "parameter is not valid" please inform where the problem is

              murali krishna

              modified on Monday, February 25, 2008 1:36 AM

              G Offline
              G Offline
              Giorgi Dalakishvili
              wrote on last edited by
              #6

              Try this: How To Read and Write BLOB Data by Using ADO.NET with Visual C# .NET[^]

              #region signature my articles #endregion

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups