简体   繁体   English

如何在Asp.Net C#中将图像上传到SQL数据库

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

I have a website which has 3 image boxes within the header section. 我有一个网站,该网站的标题部分包含3个图像框。 I've worked on writing some jQuery that will allow for my images to fade in and out, which works like so: 我已经编写了一些jQuery,使我的图片可以淡入和淡出,如下所示:

<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. 但是,每个盒子中将有7张照片以幻灯片方式通过。

The main issue is that I've built a little SQL database in my project that contains the following: 主要问题是我在项目中建立了一个包含以下内容的小型SQL数据库:

照片数据库

And here are the 3 image boxes in the header: 这是标题中的3个图像框:

标题图片栏

My table is called tbl_Photos , and the database is called DetailPhotos.dbo . 我的表称为tbl_Photos ,数据库称为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. 您可以在网站根目录的“图像”文件夹中看到我的图像,例如detail_1.jpg 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? 我是否需要创建一些特殊的SQL才能将照片从“图像”文件夹移动到数据库? And is it possible to populate the 3 boxes from the database with the images? 是否可以在数据库中用图像填充3个框?

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. 因此,也许将您的图像属性更改为img_path,并将相对文件路径放置在此位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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