一个asp按钮将多个图像插入数据库 [英] multiple images insert into database with one asp button

查看:54
本文介绍了一个asp按钮将多个图像插入数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,先生,


如何使用一个asp.net按钮将多个图像插入数据库?

请用示例代码或链接指导我.

谢谢
Jaheena

Hi sir,


How can I insert multiple images into database with one asp.net button ?

Please guide me with sample codes or links.

Thanks
Jaheena

推荐答案

如何执行此操作将取决于您存储图像的方式:如果数据库中每行总是有五张图像,那么这是一个命令.否则,您将需要发出单独的行INSERT命令.
假设每行一张图像:

1)启用SQL Server Management Studio.
2)连接,然后打开要将图像添加到的数据库.
3)展开表,然后添加带有适当索引字段的新表,或者右键单击该表并选择设计.
4)添加一个名为"myImage"的字段,并将其数据类型设置为"image".允许为空.
5)关闭SQL Server Management Studio.
要将图像添加到表中(我将假设一个新记录,该表具有一个Identity字段,而只是myImage列):
How you do this will depend on how you store your images: if you always have five images per row in the database, then it is one command. Otherwise you will need to issue separate row INSERT commands.
Assuming it is one image per row:

1) Bring up SQL Server Management Studio.
2) Connect, and open the database you want to add the image to.
3) Expand the tables, and either add a new table with an appropriate index field, or right click teh table and select design.
4) Add a field called "myImage", and make its datatype "image". Allow nulls.
5) Close SQL Server Management studio.
To add images to the table (I will assume a new record, the table has an Identity field, and just teh myImage column):
using (SqlConnection con = new SqlConnection(connectionString))
    {
    using (SqlCommand com = new SqlCommand("INSERT INTO myTable (myImage) VALUES (@IM)", con))
        {
        byte[] imageData = File.ReadAllBytes(@"F:\Temp\Picture1.jpg");
        com.Parameters.AddWithValue("@IM", imageData);
        com.ExecuteNonQuery();
        imageData = File.ReadAllBytes(@"F:\Temp\Picture2.jpg");
        com.Parameters["@IM"].Value = imageData;
        com.ExecuteNonQuery();
        }
    }

如果每行有多个图像,则只需添加第二个图像字段,并将其包含在INSERT语句中.

If it is multiple images per row, then just add a second image field, and include it in the INSERT statement.


这篇关于一个asp按钮将多个图像插入数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆