简体   繁体   中英

How to Upload Images into SQL Database in Asp.Net C#

I have a website which has 3 image boxes within the header section. I've worked on writing some jQuery that will allow for my images to fade in and out, which works like so:

<script src="/Scripts/jquery-2.1.1.js" type="text/javascript"></script> 
 <script type="text/javascript">
    $(document).ready(function (){
        setTimeout(function (){
            $('#Image1').fadeOut('slow');                                   
        }, 3000);                           
    });

    var fadeBack = function () {
        setTimeout(function () {
            $('#Image1').fadeIn('slow');
        }, 6000);
    };

    fadeBack();
</script>        

However, each one of the boxes will have 7 photos that pass through it in slideshow fashion.

The main issue is that I've built a little SQL database in my project that contains the following:

照片数据库

And here are the 3 image boxes in the header:

标题图片栏

My table is called tbl_Photos , and the database is called DetailPhotos.dbo . The table structure is setup as:

  • intPhotoID, int, Primary Key
  • strPhotoName, varchar(50)
  • imgPhoto, image

You can see my images like detail_1.jpg in the Images folder in the root of the site. I was told I could create a slideshow of the images from a database, but I don't know how to get the images " inside " of the database. How do I accomplish this? Will I have to create some special SQL to move photos from the Images folder to the database? And is it possible to populate the 3 boxes from the database with the images?

This is a new venture for me and I would like to lock this in mind, so I know for future use. Thanks.

I would suggest that instead of attempting to store an image in the db to store a filepath to that image in the db. Then you can get that filepath from the db and pass it in as the source for your image or images.

So maybe change your image attribute to say, img_path and place the relative file paths in this location.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM