AnimeGalleries [dot] NetAnimeWallpapers [dot] ComAnimeLyrics [dot] ComAnimePedia [dot] ComAnimeGlobe [dot] Com


User Tag List

Closed Thread
Results 1 to 2 of 2

Thread: [Help - C#] Get images from SQL

  1. #1
    boopaloop! IFS has a reputation beyond repute IFS has a reputation beyond repute IFS has a reputation beyond repute IFS has a reputation beyond repute IFS has a reputation beyond repute IFS has a reputation beyond repute IFS has a reputation beyond repute IFS has a reputation beyond repute IFS has a reputation beyond repute IFS has a reputation beyond repute IFS has a reputation beyond repute IFS's Avatar
    Gil
    25,635.11
    Gender
    My Mood
    Angelic
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Latest Post
    05-12-2012 02:03 PM
    User Info Thanks / Tagging Info Gifts / Achievements / Awards vBActivity Stats
    Join Date
    Jan 2009
    Location
    I live in South Africa, Kempton Park, Birchliegh
    Age
    35
    Threads
    17
    Posts
    1,037
    Rep Power
    1177

    Default [Help - C#] Get images from SQL

    Does anyone here know how I can retrieve the images from my database into a datalist or a datagrid?

    here is my code to read it into the database:

    Code:
    if (FileUpload1.PostedFile != null && FileUpload1.PostedFile.FileName != "")
    {
    	byte[] imageSize = newbyte[FileUpload1.PostedFile.ContentLength];
    	HttpPostedFile uploadedImage = FileUpload1.PostedFile;
    	uploadedImage.InputStream.Read(imageSize, 0, (int)FileUpload1.PostedFile.ContentLength);
    	
    	// Create SQL Connection 
    	SqlConnection conn = newSqlConnection(@"User ID=sa;
    			Password=evolution;
    			Initial Catalog=PE_Reunion;
    			Data Source=(local)");
    	
    	// Create SQL Command 
    	SqlCommand cmd = newSqlCommand();
    	cmd.CommandText = "INSERT INTO Demo(DemoImageName,DemoImage)" + "
    			VALUES ('" + TextBox1.Text + "', @Image)";
    	cmd.CommandType = CommandType.Text;
    	cmd.Connection = conn;
    	SqlParameter ImageName = newSqlParameter("@ImageName", SqlDbType.VarChar, 50);
    	ImageName.Value = FileUpload1.FileName;
    	cmd.Parameters.Add(ImageName);
    	SqlParameter UploadedImage = newSqlParameter("@Image", SqlDbType.Image, imageSize.Length);
    	UploadedImage.Value = imageSize;
    	cmd.Parameters.Add(UploadedImage);
    	conn.Open();
    	int result = cmd.ExecuteNonQuery();
    	conn.Close();
    	if (result > 0) Label3.Text = "Demo File Uploaded and Saved";
    	Response.Redirect("photos.aspx");
    }
    Last edited by FlashD; 03-10-2010 at 11:09 AM. Reason: When posting code use the [code], [php] or [html] tag

    Millionaire Campaign:
    Making millionaires out of everyone


    This was unknowingly
    brought to you
    by .Elmer
    and knowingly
    sponsored by Baka Baka!!!



    avi made by my sweet cousin .Elmer


  2. #2
    Junior Member Reke is on a distinguished road Reke's Avatar
    Gil
    120.00
    Gender
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Latest Post
    03-25-2010 07:24 AM
    User Info Thanks / Tagging Info Gifts / Achievements / Awards vBActivity Stats
    Join Date
    Mar 2010
    Threads
    1
    Posts
    6
    Rep Power
    0

    Default

    Try to add DataSource component on your form and connect your image with it.

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. Having Trouble uploading images for avater and sig
    By Razor Clarence in forum Site Issues / Questions
    Replies: 2
    Last Post: 11-11-2005, 10:23 PM
  2. A Can't Upload Images
    By pimohdaimaoh in forum Art Forum
    Replies: 12
    Last Post: 07-02-2005, 05:50 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts