binding blob with picturebox

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • virtuoso
    New Member
    • May 2010
    • 10

    #1

    binding blob with picturebox

    Hi,
    I'm a beginer in c sharp and I can't pass over a problem. I would like to bind a blob field (mysql) with a picturebox in c sharp;

    here is the code:

    Code:
    string query = "Select name,director,picture from Movies where Movies.name='" + search + "'";
                    //create command and assign the query and connection from the constructor
                    MySqlCommand cmd = new MySqlCommand(query, connection);
    
                    //Execute command
                    MySqlDataReader dr;
                    
                    dr = cmd.ExecuteReader();
                    if (dr.HasRows)
                    {
                        while (dr.Read())
                        {
                            txtname.Text = (dr["Name"] + "");
                            txtdirector.Text = (dr["Director"] + "");
                            txtactors.Text = (dr["Actors"] + " "");
                        }
                    }
                    else
                        MessageBox.Show("The movie is unavailable");


    what shall I do to extract the picture form database and put it in a picturebox
    like I put the other fields in textbox ?

    thank you in advance
    Last edited by tlhintoq; May 10 '10, 02:34 PM. Reason: [CODE] ...Your code goes between code tags [/CODE]
  • Monomachus
    Recognized Expert New Member
    • Apr 2008
    • 127

    #2
    Read this Obtaining BLOB Values from a Database

    Comment

    • virtuoso
      New Member
      • May 2010
      • 10

      #3
      I can't open the link. Anyway, befor I post the question i do a lot of reading on this topic but without result. And because of that I post the question, as a last try :)

      Comment

      • tlhintoq
        Recognized Expert Specialist
        • Mar 2008
        • 3532

        #4
        I just checked, and the MSDN page in that link works fine.
        Maybe it was a temporary problem. Please try the link again.

        Comment

        • virtuoso
          New Member
          • May 2010
          • 10

          #5
          I don't know why but my browser can't find the server. An exact answer would be much better than reading some general info about this; I tried that but since I'm a novice, without much results.

          Comment

          • tlhintoq
            Recognized Expert Specialist
            • Mar 2008
            • 3532

            #6
            An exact answer would be much better than reading some general info about this
            MSDN already wrote an entire article with example code. It's not what I would call "general information", but rather "thorough information" with examples from various situations and needs. It is several pages long, and therefore beyond a simple copy/paste to this thread.

            msdn.microsoft. com is a fairly major server to not be able to find. What country are you in? Are you in a country that filters their internet sites? I've been places where you couldn't get on Facebook or Yahoo because they weren't in keeping with the moral code of the country. But I've never seen Microsoft.com get filtered out. Maybe your DNS provider is having issues. Google provided free DNS service. You can change/add their hosting. IP Addresses 8.8.8.8 and 8.8.4.4

            Once you have your internet/ISP problems resolved the article should make for a good read and give you many good examples that you can apply not only to this one project, but to future projects and your coding education/career.

            Comment

            • tlhintoq
              Recognized Expert Specialist
              • Mar 2008
              • 3532

              #7
              Perhaps the problem is the *link* not the address. Try just copy/paste this address into your browser.

              http://msdn.microsoft. com/en-us/library/87z0hy49(VS.71) .aspx

              Comment

              • virtuoso
                New Member
                • May 2010
                • 10

                #8
                Thank you, I'll try then to fix the problem.
                (I'm from Romania)

                Comment

                • virtuoso
                  New Member
                  • May 2010
                  • 10

                  #9
                  I manage to take the picture form the database but I can't put it in the picturebox because it give an erroar : "A generic error occurred in GDI+."

                  Code:
                   MySqlDataReader dr;
                               dr = cmd.ExecuteReader();
                                  
                               if (dr.HasRows)
                               {
                                  while (dr.Read())
                                  {
                                  MemoryStream ms = new MemoryStream((byte[])dr["poza"]);
                                  pictureBox.Image = Image.FromStream(ms);  //here it givs the error
                                  }
                              }
                  I verifyed with watch the value of "dr["poza"]" and is not empty. I read about the error but it seems to apper form many reasons.

                  Comment

                  Working...