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. Mobile Development
  3. Mobile
  4. Displaying an Image in an SQL CE Server application

Displaying an Image in an SQL CE Server application

Scheduled Pinned Locked Moved Mobile
databasehelpcsharpperlhtml
1 Posts 1 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.
  • S Offline
    S Offline
    SpeBeeTo
    wrote on last edited by
    #1

    Hello, This is the first time I've posted anything, but I'd like to thank everyone for all the wonderful infos they have posted. I realy have learned a lot. I am working on a program that has been modified from Brian Nash's "Compact Framework Movie Collection Manager". He (and I) uses SQL Server CE and C#, but I would like to add an image to the database. Basically, all I want to accomplish is that an image is displayed for a particular "Movie ID." I searched on the internet and found the following snippet: 1. Create Database - did that -- no problem. 2. Create Table using ExecuteNonQuery() string sqlCreateImageTable = "CREATE TABLE Photos (photoID int IDENTITY (1, 1) NOT NULL," + "name nvarchar(50) NULL, photo image NULL)"; Added this, no problem (no errors) 3. Read bytes of Image from FileStream FileStream fs = new FileStream(photoPath, FileMode.Open); int photoLength = (int)fs.Length; byte[] photoBytes = new byte[photoLength]; int n = fs.Read(photoBytes, 0, photoLength); Not sure where to add this...... 4. Insert Image into Sql Ce string connectionString = @"Data Source =\PhotoAlbum.sdf"; SqlCeConnection oConn = new SqlCeConnection(connectionString); oConn.Open(); SqlCeCommand oCmd = oConn.CreateCommand(); oCmd.CommandText = "INSERT INTO Photos (name, photo) VALUES (?, ?)"; Added this, no problems (i.e. no errors) here..... oCmd.Parameters.Add("name", label3.Text); oCmd.Parameters.Add("photo", SqlDbType.Image).Value = photoBytes; Added this, but since I don't have an image, I don't see anything. (??) oCmd.Prepare() ; int rows = oCmd.ExecuteNonQuery(); oConn.Close(); But it doesn't seem to work quite well. I am having problems in Step 3..... (particularly photoBytes).... Any help would be greatly appreciated. If I'm too vague, I'm sorry. I'm a newbie at this C# thing and am just starting with SQL stuff. I've been mainly an HTML/Perl/CSS type of programmer. This is, by far, the toughest code I've worked on. Don't cut me down for my lack of knowledge! Thanks, M.

    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