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. Database & SysAdmin
  3. Database
  4. ADO.Net updating a BLOB

ADO.Net updating a BLOB

Scheduled Pinned Locked Moved Database
csharpquestionannouncement
2 Posts 2 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.
  • M Offline
    M Offline
    MrGlover
    wrote on last edited by
    #1

    I have been pawing all over the ADO.Net references and still can't see an obvious way to update a BLOB field. Any clues? TIA

    Richard DeemingR 1 Reply Last reply
    0
    • M MrGlover

      I have been pawing all over the ADO.Net references and still can't see an obvious way to update a BLOB field. Any clues? TIA

      Richard DeemingR Offline
      Richard DeemingR Offline
      Richard Deeming
      wrote on last edited by
      #2

      Look at ".Net Data Access Architecture Guide" on MSDN: Writing BLOB Data to the Database The following code shows how to use ADO.NET to write binary data obtained from a file to an image field in SQL Server.

      public void StorePicture( string filename ) {
      // Read the file into a byte array
      FileStream fs = new FileStream( filename, FileMode.Open, FileAccess.Read );
      byte[] imageData = new Byte[fs.Length];
      fs.Read( imageData, 0, (int)fs.Length );
      fs.Close();

      SqlConnection conn = new SqlConnection("Connection String");
      SqlCommand cmd = new SqlCommand("StorePicture", conn);
      cmd.CommandType = CommandType.StoredProcedure;
      cmd.Parameters.Add("@filename", filename );
      cmd.Parameters["@filename"].Direction = ParameterDirection.Input;
      cmd.Parameters.Add("@blobdata", SqlDbType.Image);
      cmd.Parameters["@blobdata"].Direction = ParameterDirection.Input;
      // Store the byte array within the image field
      cmd.Parameters["@blobdata"].Value = imageData;
      try {
      conn.Open();
      cmd.ExecuteNonQuery();
      }
      catch {
      throw;
      }
      finally {
      conn.Close();
      }
      }

      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

      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