Click here to Skip to main content
12,067,928 members (29,889 online)
Rate this:
Please Sign up or sign in to vote.
See more: VB database VB.NET , +
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 1:18am
Edited 4-Mar-11 8:46am
Agnahim 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>

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web04 | 2.8.160208.1 | Last Updated 4 Mar 2011
Copyright © CodeProject, 1999-2016
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