在SQL数据库中添加多个图像 [英] Adding multiple images in SQL database

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

问题描述

所以问题是我可以在我的vb.net应用程序中为每条记录添加1个图像。我想要做的是选择多个图像并将每个图像放在不同的列中。因此,1条记录将有多个不同的图像可供查看。



我已经制作了代码,我可以将1个图像添加到数据库并查看它,但我需要添加动态的图像,根据我的选择,它将允许我将我选择的图像添加到1条记录中。



这是我现在的代码:



So the problem is I am able to add 1 image per record in my vb.net application. What I am wanting to do is select multiple images and have each image placed in a different column. So 1 record will have multiple different images to view.

I have made the code where I can add 1 image to the database and view it, but I need to add the images dynamically, based upon my selection it will allow me to add what.ever images I have select into 1 record.

here is my code for what I have right now:

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click


       Dim Files As New OpenFileDialog
       Files.Filter = "Image(*.JPG;*.PNG;*.GIF)|*.jpg;*.png;*.gif"
       ' Allow the user to select multiple images.
       Files.Multiselect = True
       Files.Title = "Select an image"
       Files.ShowDialog()
       PictureBox1.Image = Image.FromFile(Files.FileName)




       Try
           Dim sqlcon As New SqlConnection("SQLstatement")
           Dim sqladapt = New SqlDataAdapter("Select * from [Table]", sqlcon)


           sqlcon.Open()
           Dim cmd As SqlClient.SqlCommand
           Dim sql As String = "insert into [Table] values(@img)"
           cmd = New SqlClient.SqlCommand(sql, sqlcon)

           Using ms As MemoryStream = New MemoryStream()


               Dim bm As Bitmap = New Bitmap(PictureBox1.Image)
               bm.Save(ms, PictureBox1.Image.RawFormat)

               Dim arrPic() As Byte = ms.GetBuffer()

               cmd.Parameters.AddWithValue("@img", arrPic)



               cmd.ExecuteNonQuery()
           End Using
           sqlcon.Close()

           MessageBox.Show("New Record Added")

       Catch ex As Exception



           End Try





我尝试过:



我找不到有关多个图像被添加到一条记录的大量信息,所以我无法尝试纠正自己的问题。



What I have tried:

I could not find much information on multiple images being added to one record, so I haven't been able to try to correct my own problem.

推荐答案

检查:

在SQL Server中存储或保存图像 [ ^ ]

使用OLEDB将图像插入MS Access文件 [ ^ ]
Check this:
Store or Save images in SQL Server[^]
Inserting images into MS Access file using OLEDB[^]


这篇关于在SQL数据库中添加多个图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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