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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. image retrieving problem in sql server 2000

image retrieving problem in sql server 2000

Scheduled Pinned Locked Moved ASP.NET
graphicshelpdatabasesql-serverwinforms
4 Posts 3 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.
  • P Offline
    P Offline
    Pankaj Garg
    wrote on last edited by
    #1

    Following is the code , i am doing , but the error is occuring while the execution of last line. Error A generic error occurred in GDI+. Where I am doing wrong SqlConnection con = new SqlConnection(connectionstring); con.Open(); SqlCommand cmd=new SqlCommand(); cmd.CommandText = "spSelect_a"; cmd.Connection = con; cmd.CommandType = CommandType.StoredProcedure; DataSet ds = new DataSet(); SqlDataAdapter ad = new SqlDataAdapter(cmd); ad.Fill(ds); byte[] b = (byte[])cmd.ExecuteScalar(); MemoryStream ms = new MemoryStream(); ms.Write(b, 0, b.Length); Bitmap bmp = new Bitmap(ms); **bmp.Save(Response.OutputStream,ImageFormat.Bmp);**

    If you have an apple & I have an apple and we exchange our apples, then each of us will still have only one apple but if you have an idea & I have an idea and we exchange our ideas, then each of us will have two ideas!

    N T 2 Replies Last reply
    0
    • P Pankaj Garg

      Following is the code , i am doing , but the error is occuring while the execution of last line. Error A generic error occurred in GDI+. Where I am doing wrong SqlConnection con = new SqlConnection(connectionstring); con.Open(); SqlCommand cmd=new SqlCommand(); cmd.CommandText = "spSelect_a"; cmd.Connection = con; cmd.CommandType = CommandType.StoredProcedure; DataSet ds = new DataSet(); SqlDataAdapter ad = new SqlDataAdapter(cmd); ad.Fill(ds); byte[] b = (byte[])cmd.ExecuteScalar(); MemoryStream ms = new MemoryStream(); ms.Write(b, 0, b.Length); Bitmap bmp = new Bitmap(ms); **bmp.Save(Response.OutputStream,ImageFormat.Bmp);**

      If you have an apple & I have an apple and we exchange our apples, then each of us will still have only one apple but if you have an idea & I have an idea and we exchange our ideas, then each of us will have two ideas!

      N Offline
      N Offline
      N a v a n e e t h
      wrote on last edited by
      #2

      Pankaj Garg wrote:

      A generic error occurred in GDI+.

      What does the InnerException says ?

      All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia My Website | Ask smart questions

      P 1 Reply Last reply
      0
      • N N a v a n e e t h

        Pankaj Garg wrote:

        A generic error occurred in GDI+.

        What does the InnerException says ?

        All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia My Website | Ask smart questions

        P Offline
        P Offline
        Pankaj Garg
        wrote on last edited by
        #3

        This is he only exception i am getting , the external exception was handled by the user code , was written on the Exception title.

        If you have an apple & I have an apple and we exchange our apples, then each of us will still have only one apple but if you have an idea & I have an idea and we exchange our ideas, then each of us will have two ideas!

        1 Reply Last reply
        0
        • P Pankaj Garg

          Following is the code , i am doing , but the error is occuring while the execution of last line. Error A generic error occurred in GDI+. Where I am doing wrong SqlConnection con = new SqlConnection(connectionstring); con.Open(); SqlCommand cmd=new SqlCommand(); cmd.CommandText = "spSelect_a"; cmd.Connection = con; cmd.CommandType = CommandType.StoredProcedure; DataSet ds = new DataSet(); SqlDataAdapter ad = new SqlDataAdapter(cmd); ad.Fill(ds); byte[] b = (byte[])cmd.ExecuteScalar(); MemoryStream ms = new MemoryStream(); ms.Write(b, 0, b.Length); Bitmap bmp = new Bitmap(ms); **bmp.Save(Response.OutputStream,ImageFormat.Bmp);**

          If you have an apple & I have an apple and we exchange our apples, then each of us will still have only one apple but if you have an idea & I have an idea and we exchange our ideas, then each of us will have two ideas!

          T Offline
          T Offline
          Tarun Dudhatra
          wrote on last edited by
          #4

          I think this code will work just try it. And let me know it's working or not just change image format as per requirement and variable name and also that database fieldname. Response.Clear(); Response.ContentType = "image/jpeg"; System.Drawing.Image image = null; Cmd = new SqlCommand("SELECT fieldname FROM tablename where field='" + id + "'", Con); Cmd.CommandType = CommandType.Text; SqlDataReader Dr = Cmd.ExecuteReader(); if (Dr.Read()) { byte[] imageData = (byte[])Dr[0]; MemoryStream memStream = new MemoryStream(imageData); image = System.Drawing.Image.FromStream(memStream); image.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg); }

          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