本文介绍了将多个PictureBox图像存储到数据库中(同一ID为10个图像)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我是.Net的新手.我知道如何将单个图片框图像存储/检索到数据库中.在我的项目中,我想将10个Picturebox图像存储/检索到数据库中.

我尝试了以下方法:

Hi all,

I am new to .Net. I know how to store/retrieve a single picture box image into a database. In my project I want to store/retrieve 10 picturebox images into a database.

I tried the following:

Dim Names(9) As String
                Names(0) = pbLT.Name
                Names(1) = pbLI.Name
                Names(2) = pbLM.Name
                Names(3) = pbLR.Name
                Names(4) = pbLL.Name
                Names(5) = pbRT.Name
                Names(6) = pbRI.Name
                Names(7) = pbRM.Name
                Names(8) = pbRR.Name
                Names(9) = pbRL.Name
                Dim pictures(9) As Image
                pictures(0) = pbLT.Image
                pictures(1) = pbLI.Image
                pictures(2) = pbLM.Image
                pictures(3) = pbLR.Image
                pictures(4) = pbLL.Image
                pictures(5) = pbRT.Image
                pictures(6) = pbRI.Image
                pictures(7) = pbRM.Image
                pictures(8) = pbRR.Image
                pictures(9) = pbRL.Image
                Dim pb As New PictureBox
                pb.Image = pictures(0)
                Dim i As Integer = 0
                For index As Integer = 0 To pictures.Length - 1
                    Names(i) = Names(i).Substring(Names(i).Length - 2)
                    pb.Name = Names(i)
                    pb.Image = pictures(index) 
For index As Integer = 0 To pictures.Length - 1 
 
Dim cmd As New SqlCommand("insert into Register(RegCode,picID,binpicData)values(@RegCode,@picID,@binpicData)", con) 
 
Dim mstream As New MemoryStream() 
 
Dim pic As Byte() = mstream.ToArray() 
cmd.Parameters.Add(
 
New SqlParameter("@RegCode", SqlDbType.NVarChar, 50)).Value = txtMI.Text 
cmd.Parameters.Add(
 
New SqlParameter("@picID", SqlDbType.Char, 2)).Value = pb.Name
cmd.Parameters.AddWithValue(
"@binpicData", pic)
 
Try
con.Open()
cmd.ExecuteNonQuery()
con.Close()
 
Catch err As SqlException 
 
End Try
pb.Image.Dispose()
mstream.Close()
i = i + 1
 
Next


我已经在上面完成了上述工作,我试图将数据插入数据库,但是事情是,所有字段中都只插入了第一个图片框图像二进制数据.

任何帮助将不胜感激.

谢谢.

更正了不良标签.


I have done like the above here I am trying to insert data into the database but the thing is only first picture box image binary data is inserting in all fields.

Any help is greatly appreciated.

Thanks.

Corrected bad tags. No c# in here.

推荐答案

<pictures>
  <picture1><![[CDATA[....binary data here....</picture1>
  <picture2><![[CDATA[....binary data here....</picture2>
etc...
<pictures>

The Sql table field will contain this information but you will have to 
parse it when inserting/updating and selecting.

Hope this helps</pictures></pictures>


这篇关于将多个PictureBox图像存储到数据库中(同一ID为10个图像)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 17:42