Results 1 to 6 of 6

Thread: How to use ADO.NET Entity Framework to obtain images from database

  1. #1
    Join Date
    Feb 2010
    Posts
    669

    question How to use ADO.NET Entity Framework to obtain images from database

    Hi all,

    How to use the ADO.NET Entity Framework that build the data access layer, to achieve the picture saved to the database as well as to obtain images from the database. I have a project on it. Please send some solution as soon as possible. Thanks in advance.

  2. #2
    Dr. V Guest

    Use ADO.NET Entity Framework to obtain images from database

    You nee to creating a data table to build the data access layer. The first step, create a data table.In the table requires a field to save the image, type set to image, the code is as follows:

    Code:
    Create table [dbo]. [Images] (
    [id] [int] IDENTITY (1,1) NOT NULL,
    [imagefile123] [image_abc] NOT NULL)
    The second step, build the data access layer. This type of data insertion and general basic SQL types, but in. net 3.5 programmers working on the platforms do not need to think too much about access to the database specific code, we can choose ADO.NET Entity Framework.

  3. #3
    Join Date
    May 2008
    Posts
    2,680

    Re: How to use ADO.NET Entity Framework to obtain images from database

    For new project, select the ADO.NET Entity Data Model, the wizard to establish a connection to the database, the wizard to select the database table just created images, the wizard after the end of the project will add a edmx types of files, the default interface will be Open the auto-generated entity class diagram, we have selected in the wizard of all forms are the default corresponds to an entity class name is the same as with the data sheet, where the images correspond to the entity classes are also images, but if such a default would cause ambiguity. Check and reply.

  4. #4
    Join Date
    Nov 2005
    Posts
    3,026

    Re: How to use ADO.NET Entity Framework to obtain images from database

    You need to declare an image type of a variable may be called a img, image img = new image ();, then create a entities object, Entities X = new XXEntities (). ASP. net WebAdd page FileUpload control, the control provides a property Posted File can Servers Provide an input output stream, you can just select a picture for us to read the server's Memory, The code is as follows:
    Code:
    System.IO.Stream stream = FileUpload123.PostedFile.InputStream;
    byte [] buffer = new byte [stream.Length];
    stream.Read (buffer, 0, (int) stream.Length);
    stream.Close ();
    img123.imagefile123 = buffer;
    The next step is to represent images of the byte array deposited in the database, the code is as follows:
    Code:
    123.AddToimageSet (t);
    123.SaveChanges ();
    This picture into the database operation is complete.

  5. #5
    Join Date
    Apr 2008
    Posts
    3,295

    ADO.NET Entity Framework to obtain images from database

    To obtain images from the database and displayed to the ASP.NET Page into an Image control in showImage.aspx named Image1, because image is taken from the database to a binary file, thus not using the file system image has its own URL, we can directly set its URL to Images on the site in the path, the solution is as follows: New addition dedicated to providing a picture of asp.net page getImage.aspx, its function is only to read images from the database, using Response.BinaryWrite () the way pictures of data stream output, then you may have thought, we will image1's URL is set to the above-mentioned getImage.aspx, if you need a picture id and the like according to the information to choose the asp.net page that we provide an additional id parameter is be. All the best.

  6. #6
    Join Date
    Apr 2008
    Posts
    3,522

    Re: How to use ADO.NET Entity Framework to obtain images from database

    Web site images can be saved to the file system, that is a special directory for the images stored, so that the storage coupled with Database to save the picture path information, I believe that many websites are so choice. Use the below code.
    i
    Code:
    nt id = int.Parse (Request.QueryString [ "id123"]);
    image img123 = 123.imageSet.Where (i => i.ID == id123). First ();
    Response.BinaryWrite (img123.imageFile);
    showImage.aspx for the Image1 control to set the URL to "getImage.aspx? id = 1" (in the cs code programming of settings, can also aspx in a static setting), you can correctly point to the need of the pictures. Best of luck.

Similar Threads

  1. Changing the entity of a datatype
    By GOOL in forum Software Development
    Replies: 6
    Last Post: 06-01-2011, 08:31 AM
  2. Inserting and retrieving images from Database
    By Ainsley in forum Software Development
    Replies: 3
    Last Post: 25-01-2010, 01:49 PM
  3. Entity Referencing
    By Bhardwaj in forum Software Development
    Replies: 5
    Last Post: 20-01-2010, 08:48 AM
  4. Storing images in SQL database using Asp.net
    By Booth in forum Software Development
    Replies: 2
    Last Post: 17-01-2009, 06:25 PM

Tags for this Thread

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
  •  
Page generated in 1,711,724,390.13475 seconds with 17 queries