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. Image in Database [modified]

Image in Database [modified]

Scheduled Pinned Locked Moved C#
databasehelp
10 Posts 5 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.
  • H Offline
    H Offline
    Hossein Afyuoni
    wrote on last edited by
    #1

    hello world! I wanted to access my Images In Database and I write these codes :

    byte[] buffer2 = (byte[])dsPicture.Tables["documentImageTable"].Rows[3]["diImage"];
    MemoryStream stream2 = new MemoryStream(buffer2);
    pictureBox2.Image = Image.FromStream(stream2);
    stream2.Close();

    But It have this error: Object reference not set to an instance of an object. Tanx world...

    modified on Monday, October 20, 2008 1:40 PM

    G 1 Reply Last reply
    0
    • H Hossein Afyuoni

      hello world! I wanted to access my Images In Database and I write these codes :

      byte[] buffer2 = (byte[])dsPicture.Tables["documentImageTable"].Rows[3]["diImage"];
      MemoryStream stream2 = new MemoryStream(buffer2);
      pictureBox2.Image = Image.FromStream(stream2);
      stream2.Close();

      But It have this error: Object reference not set to an instance of an object. Tanx world...

      modified on Monday, October 20, 2008 1:40 PM

      G Offline
      G Offline
      Guffa
      wrote on last edited by
      #2

      You should turn option strict on in your project, so that you get an error message telling you that you are using the variable stream1 that is not declared anywhere.

      Despite everything, the person most likely to be fooling you next is yourself.

      E H P N 5 Replies Last reply
      0
      • G Guffa

        You should turn option strict on in your project, so that you get an error message telling you that you are using the variable stream1 that is not declared anywhere.

        Despite everything, the person most likely to be fooling you next is yourself.

        E Offline
        E Offline
        Eslam Afifi
        wrote on last edited by
        #3

        Guffa wrote:

        option strict

        :rolleyes:

        Eslam Afifi

        1 Reply Last reply
        0
        • G Guffa

          You should turn option strict on in your project, so that you get an error message telling you that you are using the variable stream1 that is not declared anywhere.

          Despite everything, the person most likely to be fooling you next is yourself.

          H Offline
          H Offline
          Hossein Afyuoni
          wrote on last edited by
          #4

          My problem not solve ... :(

          if(Human.live) { Human.peaceful = false; while(true) { Human.love(Human girl, Human Boy); } }

          G 1 Reply Last reply
          0
          • H Hossein Afyuoni

            My problem not solve ... :(

            if(Human.live) { Human.peaceful = false; while(true) { Human.love(Human girl, Human Boy); } }

            G Offline
            G Offline
            Guffa
            wrote on last edited by
            #5

            What do you mean? You open stream2 and close stream1 (which doesn't exist in the code that you posted), that is definitely a problem. It might not be your only problem, though. On which line do you get the error message? Edit: You should name your variables to something more descriptive than stream1 and stream2, that way you are not so likely to mix them up.

            Despite everything, the person most likely to be fooling you next is yourself.

            1 Reply Last reply
            0
            • G Guffa

              You should turn option strict on in your project, so that you get an error message telling you that you are using the variable stream1 that is not declared anywhere.

              Despite everything, the person most likely to be fooling you next is yourself.

              P Offline
              P Offline
              Paul Conrad
              wrote on last edited by
              #6

              Guffa wrote:

              option strict on

              Is there even one in C#?

              "The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon "Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham

              G 1 Reply Last reply
              0
              • P Paul Conrad

                Guffa wrote:

                option strict on

                Is there even one in C#?

                "The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon "Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham

                G Offline
                G Offline
                Guffa
                wrote on last edited by
                #7

                Paul Conrad wrote:

                Is there even one in C#?

                No, you are right. There isn't. I was thinking of VB, where such a mistake is usually caused by not using strict mode.

                Despite everything, the person most likely to be fooling you next is yourself.

                1 Reply Last reply
                0
                • G Guffa

                  You should turn option strict on in your project, so that you get an error message telling you that you are using the variable stream1 that is not declared anywhere.

                  Despite everything, the person most likely to be fooling you next is yourself.

                  H Offline
                  H Offline
                  Hossein Afyuoni
                  wrote on last edited by
                  #8

                  I writed correctly in my codes but I wrong in this... what I do for solve this error ...

                  if(Human.live) { Human.peaceful = false; while(true) { Human.love(Human girl, Human Boy); } }

                  1 Reply Last reply
                  0
                  • G Guffa

                    You should turn option strict on in your project, so that you get an error message telling you that you are using the variable stream1 that is not declared anywhere.

                    Despite everything, the person most likely to be fooling you next is yourself.

                    N Offline
                    N Offline
                    nelsonpaixao
                    wrote on last edited by
                    #9

                    Use this routine (doesn´t crash with *.gifs) :omg:

                    // read image
                    public static byte[] ReadFile(string image_path)
                    {
                    byte[] data = null;

                    FileInfo file_info = new FileInfo(image_path);
                    long bytes_count = file_info.Length;

                    FileStream file_stream = new FileStream(image_path, FileMode.Open, FileAccess.Read);

                    BinaryReader br = new BinaryReader(file_stream);

                    data = br.ReadBytes((int)bytes_count);
                    return data;
                    }

                    nelsonpaixao@yahoo.com.br trying to help & get help

                    H 1 Reply Last reply
                    0
                    • N nelsonpaixao

                      Use this routine (doesn´t crash with *.gifs) :omg:

                      // read image
                      public static byte[] ReadFile(string image_path)
                      {
                      byte[] data = null;

                      FileInfo file_info = new FileInfo(image_path);
                      long bytes_count = file_info.Length;

                      FileStream file_stream = new FileStream(image_path, FileMode.Open, FileAccess.Read);

                      BinaryReader br = new BinaryReader(file_stream);

                      data = br.ReadBytes((int)bytes_count);
                      return data;
                      }

                      nelsonpaixao@yahoo.com.br trying to help & get help

                      H Offline
                      H Offline
                      Hossein Afyuoni
                      wrote on last edited by
                      #10

                      Mr nelsonpaixao, my Image in database And not in file ...

                      if(Human.live)
                      {
                      Human.peaceful = false;
                      while(true)
                      {
                      Human.love(Human girl, Human Boy);
                      }
                      }

                      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