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. Blobs are driving me insane!!!!!

Blobs are driving me insane!!!!!

Scheduled Pinned Locked Moved C#
databasecomgraphicshelpannouncement
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.
  • K Offline
    K Offline
    kornstyle
    wrote on last edited by
    #1

    What I want to do is choose a bitmap file, with a opendialogbox and save the bitmap to a field named "Photo" in the "Employees" table in the northwind database. I am not sure what to do, I think that the problem is in my SQL statement. What I want to do is pick a bitmap and save it to a mdb database. I am using the northwind database. Here is my code. I have been reading on this and have been able to copy a bitmap from the "Photo" field in the "Employees" table in the northwind database, to a field in the same table that I made named Photo2. private void Form1_Load(object sender, System.EventArgs e) { this.oleDbDataAdapter1.Fill(ds1, "Employees"); IDTxtBx.DataBindings.Add("Text", ds1, "Employees.EmployeeID"); firstNameTxtBx.DataBindings.Add("Text", ds1, "Employees.FirstName"); bm = BindingContext[ds1, "Employees"]; bm.PositionChanged += new EventHandler(bm_PositionChanged); bm_PositionChanged(null, null); } private void bm_PositionChanged(Object sender, EventArgs e) { image = null; this.pictureBox1.Image = null; string sqlText = "SELECT Photo FROM Employees WHERE EmployeeID=" + IDTxtBx.Text; OleDbCommand cmd = new OleDbCommand(sqlText, oleDbConnection1); this.oleDbConnection1.Open(); try { int bufferSize = 100; byte[] outbyte = new byte[bufferSize]; long retVal = 0; long startIndex = 0; OleDbDataReader dr = cmd.ExecuteReader (CommandBehavior.SequentialAccess); dr.Read(); if(!dr.IsDBNull(0)) { MemoryStream ms = new MemoryStream(); retVal = dr.GetBytes(0, startIndex, outbyte, 0, bufferSize); while(retVal == bufferSize) { ms.Write(outbyte, 0, outbyte.Length); startIndex += bufferSize; retVal = dr.GetBytes(0, startIndex, outbyte, 0, bufferSize); } ms.Write(outbyte, 0, (int)retVal - 1); image = ms.ToArray(); } } catch(Exception ex) { MessageBox.Show(ex.ToString()); } finally { this.oleDbConnection1.Close(); } if(image != null) { MemoryStream ms = new MemoryStream(image); try { } catch(Exception ex) { MessageBox.Show(ex.ToString()); } ms.Close(); } } string sqlWrite = "UPDATE " + "Employees" + " SET Photo2 = Photo WHERE EmployeeID = " + IDTxtBx.Text; OleDbCommand cmdWrite = new OleDbCommand(sqlWrite, this.ole

    J R 2 Replies Last reply
    0
    • K kornstyle

      What I want to do is choose a bitmap file, with a opendialogbox and save the bitmap to a field named "Photo" in the "Employees" table in the northwind database. I am not sure what to do, I think that the problem is in my SQL statement. What I want to do is pick a bitmap and save it to a mdb database. I am using the northwind database. Here is my code. I have been reading on this and have been able to copy a bitmap from the "Photo" field in the "Employees" table in the northwind database, to a field in the same table that I made named Photo2. private void Form1_Load(object sender, System.EventArgs e) { this.oleDbDataAdapter1.Fill(ds1, "Employees"); IDTxtBx.DataBindings.Add("Text", ds1, "Employees.EmployeeID"); firstNameTxtBx.DataBindings.Add("Text", ds1, "Employees.FirstName"); bm = BindingContext[ds1, "Employees"]; bm.PositionChanged += new EventHandler(bm_PositionChanged); bm_PositionChanged(null, null); } private void bm_PositionChanged(Object sender, EventArgs e) { image = null; this.pictureBox1.Image = null; string sqlText = "SELECT Photo FROM Employees WHERE EmployeeID=" + IDTxtBx.Text; OleDbCommand cmd = new OleDbCommand(sqlText, oleDbConnection1); this.oleDbConnection1.Open(); try { int bufferSize = 100; byte[] outbyte = new byte[bufferSize]; long retVal = 0; long startIndex = 0; OleDbDataReader dr = cmd.ExecuteReader (CommandBehavior.SequentialAccess); dr.Read(); if(!dr.IsDBNull(0)) { MemoryStream ms = new MemoryStream(); retVal = dr.GetBytes(0, startIndex, outbyte, 0, bufferSize); while(retVal == bufferSize) { ms.Write(outbyte, 0, outbyte.Length); startIndex += bufferSize; retVal = dr.GetBytes(0, startIndex, outbyte, 0, bufferSize); } ms.Write(outbyte, 0, (int)retVal - 1); image = ms.ToArray(); } } catch(Exception ex) { MessageBox.Show(ex.ToString()); } finally { this.oleDbConnection1.Close(); } if(image != null) { MemoryStream ms = new MemoryStream(image); try { } catch(Exception ex) { MessageBox.Show(ex.ToString()); } ms.Close(); } } string sqlWrite = "UPDATE " + "Employees" + " SET Photo2 = Photo WHERE EmployeeID = " + IDTxtBx.Text; OleDbCommand cmdWrite = new OleDbCommand(sqlWrite, this.ole

      J Offline
      J Offline
      Judah Gabriel Himango
      wrote on last edited by
      #2

      You're gonna need lots of COM interop for this. You'll need to setup a virtual drive that maps to Employees table, and integrate that drive into the shell. I'd look into the "C# does shell" set of articles on this site.

      Tech, life, family, faith: Give me a visit. I'm currently blogging about: Homosexuality in Christianity Judah Himango

      1 Reply Last reply
      0
      • K kornstyle

        What I want to do is choose a bitmap file, with a opendialogbox and save the bitmap to a field named "Photo" in the "Employees" table in the northwind database. I am not sure what to do, I think that the problem is in my SQL statement. What I want to do is pick a bitmap and save it to a mdb database. I am using the northwind database. Here is my code. I have been reading on this and have been able to copy a bitmap from the "Photo" field in the "Employees" table in the northwind database, to a field in the same table that I made named Photo2. private void Form1_Load(object sender, System.EventArgs e) { this.oleDbDataAdapter1.Fill(ds1, "Employees"); IDTxtBx.DataBindings.Add("Text", ds1, "Employees.EmployeeID"); firstNameTxtBx.DataBindings.Add("Text", ds1, "Employees.FirstName"); bm = BindingContext[ds1, "Employees"]; bm.PositionChanged += new EventHandler(bm_PositionChanged); bm_PositionChanged(null, null); } private void bm_PositionChanged(Object sender, EventArgs e) { image = null; this.pictureBox1.Image = null; string sqlText = "SELECT Photo FROM Employees WHERE EmployeeID=" + IDTxtBx.Text; OleDbCommand cmd = new OleDbCommand(sqlText, oleDbConnection1); this.oleDbConnection1.Open(); try { int bufferSize = 100; byte[] outbyte = new byte[bufferSize]; long retVal = 0; long startIndex = 0; OleDbDataReader dr = cmd.ExecuteReader (CommandBehavior.SequentialAccess); dr.Read(); if(!dr.IsDBNull(0)) { MemoryStream ms = new MemoryStream(); retVal = dr.GetBytes(0, startIndex, outbyte, 0, bufferSize); while(retVal == bufferSize) { ms.Write(outbyte, 0, outbyte.Length); startIndex += bufferSize; retVal = dr.GetBytes(0, startIndex, outbyte, 0, bufferSize); } ms.Write(outbyte, 0, (int)retVal - 1); image = ms.ToArray(); } } catch(Exception ex) { MessageBox.Show(ex.ToString()); } finally { this.oleDbConnection1.Close(); } if(image != null) { MemoryStream ms = new MemoryStream(image); try { } catch(Exception ex) { MessageBox.Show(ex.ToString()); } ms.Close(); } } string sqlWrite = "UPDATE " + "Employees" + " SET Photo2 = Photo WHERE EmployeeID = " + IDTxtBx.Text; OleDbCommand cmdWrite = new OleDbCommand(sqlWrite, this.ole

        R Offline
        R Offline
        Rob Graham
        wrote on last edited by
        #3

        I'm not entirely clear on what you are trying to do here. If all you are trying to do is copy the content of an existing field [photo] to another field [photo2] in the same tabel, then your update statement has no need for the parameter you are adding (and is probably confulsed by it). You don't need to read the data to copy it, it suffices to just set the value of one field to another in the update statement. If you want to write the content of the memory stream, then change the sql to

        "UPDATE Employees SET Photo2 = ? WHERE EmployeeID = " + IDTxtBx.Text;

        then the parameter you added will substitute for the ? placeholder and should work just fine It is generally not a good idea to name parameters the same as fields in the table you are addressing, aside from the confusion it causes in the code, it may also cause errors... Oledb doesn't understand named parameters like SQL server does, it expects placeholders, then matches them up by the order the paramters are added to the collection... Absolute faith corrupts as absolutely as absolute power Eric Hoffer The opposite of the religious fanatic is not the fanatical atheist but the gentle cynic who cares not whether there is a god or not. Eric Hoffer

        K 1 Reply Last reply
        0
        • R Rob Graham

          I'm not entirely clear on what you are trying to do here. If all you are trying to do is copy the content of an existing field [photo] to another field [photo2] in the same tabel, then your update statement has no need for the parameter you are adding (and is probably confulsed by it). You don't need to read the data to copy it, it suffices to just set the value of one field to another in the update statement. If you want to write the content of the memory stream, then change the sql to

          "UPDATE Employees SET Photo2 = ? WHERE EmployeeID = " + IDTxtBx.Text;

          then the parameter you added will substitute for the ? placeholder and should work just fine It is generally not a good idea to name parameters the same as fields in the table you are addressing, aside from the confusion it causes in the code, it may also cause errors... Oledb doesn't understand named parameters like SQL server does, it expects placeholders, then matches them up by the order the paramters are added to the collection... Absolute faith corrupts as absolutely as absolute power Eric Hoffer The opposite of the religious fanatic is not the fanatical atheist but the gentle cynic who cares not whether there is a god or not. Eric Hoffer

          K Offline
          K Offline
          kornstyle
          wrote on last edited by
          #4

          Thanks for Replying. Sorry if I wasn't clear. What I want to do is to write the contents of the memory stream to the field Photo2. I used the "?" but it still did not work. I am able to write the contents of the memory stream to a picture box. It is writing to the Photo2 field though because it says "Long binary data" in the Photo2 field. Any ideas

          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