Click here to Skip to main content
11,713,845 members (87,013 online)
Rate this: bad
Please Sign up or sign in to vote.
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() 
New SqlParameter("@RegCode", SqlDbType.NVarChar, 50)).Value = txtMI.Text 
New SqlParameter("@picID", SqlDbType.Char, 2)).Value = pb.Name
"@binpicData", pic)
Catch err As SqlException 
End Try
i = i + 1
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.


Corrected bad tags. No c# in here.
Posted 3-Mar-11 0:18am
Edited 4-Mar-11 7:46am
Agnahim at 3-Mar-11 11:47am
I think i get what you want to achive, but I can't see how your code can insert binary data into the database, because "pic" and "mstream" never get any data from the image.
Did you shorten your original code?

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

A solution I've used before when dealing with unknown numbers of data is to use an XML scheme;
  <picture1><![[CDATA[....binary data here....</picture1>
  <picture2><![[CDATA[....binary data here....</picture2>
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>

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 330
1 CHill60 315
2 OriginalGriff 165
3 Andy Lanng 138
4 KarstenK 110
0 Sergey Alexandrovich Kryukov 365
1 CHill60 335
2 OriginalGriff 245
3 Andy Lanng 173
4 Richard MacCutchan 150

Advertise | Privacy | Mobile
Web01 | 2.8.150819.1 | Last Updated 4 Mar 2011
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100