1,105,226 Community Members

Saving Multiple Pictures

Member Avatar
aishapot
Junior Poster in Training
74 posts since Sep 2011
Reputation Points: -3 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

I have to save 4 different pictures in my database. NSO, GoodMoral, ReportCard & TOR.
Here is my code.

Sub savepic()

        Dim str As String = "My connection"
        Dim con As New SqlClient.SqlConnection

        con.ConnectionString = str
        Dim ms As New IO.MemoryStream()

        nsopic.Image.Save(ms, nsopic.Image.RawFormat)
        goodmoralpic.Image.Save(ms, goodmoralpic.Image.RawFormat)
        repcardpic.Image.Save(ms, repcardpic.Image.RawFormat)
        torpic.Image.Save(ms, torpic.Image.RawFormat)

        Dim arrimage() As Byte = ms.GetBuffer

        Dim cmd As New SqlCommand("insert into store_image_requirements (NSOBirthC,ReportCard,GoodMoral,TOR,Student_No,Surname,First_Name,Middle_Name)values(@picture1,@picture2,@picture3,@picture4, '" & txtstud_no.Text & "', '" & txtsurname.Text & "', '" & txtfirstname.Text & "', '" & txtmiddlename.Text & "')", con)
        
        cmd.Parameters.Add(New SqlParameter("@picture", SqlDbType.Image)).Value = arrimage

        con.Open()
        cmd.ExecuteNonQuery()
        con.Close()

My problem is, it allows me to look for different picture then save it without error. But when I check on the database(MSSQL) it doesn't save the different pictures but one picture for all four requirements (NSO, GoodMoral, ReportCard & TOR). How can I be able to save multiple images in my database? Please help. Thank You

Member Avatar
aishapot
Junior Poster in Training
74 posts since Sep 2011
Reputation Points: -3 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Help :(

Member Avatar
aishapot
Junior Poster in Training
74 posts since Sep 2011
Reputation Points: -3 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Or maybe anyone can teach me how to save the picture in a folder instead?

Member Avatar
M.Waqas Aslam
Practically a Posting Shark
837 posts since Aug 2011
Reputation Points: 67 [?]
Q&As Helped to Solve: 137 [?]
Skill Endorsements: 4 [?]
Featured
 
0
 

use this code to save pic

'use this code instead of this code (        cmd.Parameters.Add(New SqlParameter("@picture", SqlDbType.Image)).Value = arrimage)
   Dim myFile As String = picture
            If picture.ToString.Length <= 1 Then
                Me.myCmd.Parameters.Add("@Picture", SqlDbType.Image).Value = Convert.DBNull
            Else
                Dim myStream As FileStream = New FileStream(myFile, FileMode.Open)
                Dim myImageBuffer() As Byte = New Byte(myStream.Length) {}
                myStream.Read(myImageBuffer, 0, myStream.Length)

                Me.myCmd.Parameters.Add("@Picture", SqlDbType.Image).Value = myImageBuffer
                myStream.Close()
            End If

regards

Member Avatar
Reverend Jim
Noli mentula
5,394 posts since Aug 2010
Reputation Points: 746 [?]
Q&As Helped to Solve: 643 [?]
Skill Endorsements: 51 [?]
Moderator
Featured
 
0
 

The query syntax to insert a picture into SQL can be found here

Member Avatar
aishapot
Junior Poster in Training
74 posts since Sep 2011
Reputation Points: -3 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

there's no problem with saving the picture. the only problem is that it doesn't save the pictures i selected for nso,goodmoral,reportcard and tor. instead it saves the same picture for the four requirements which is wrong bec i selected diff pictures for each

Question Answered as of 2 Years Ago by Reverend Jim and M.Waqas Aslam
Member Avatar
aishapot
Junior Poster in Training
74 posts since Sep 2011
Reputation Points: -3 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

I already found the solution. Thanks for the help! :)

Member Avatar
Reverend Jim
Noli mentula
5,394 posts since Aug 2010
Reputation Points: 746 [?]
Q&As Helped to Solve: 643 [?]
Skill Endorsements: 51 [?]
Moderator
Featured
 
0
 

Can you please post the solution you found? It may be of help to someone else.

Member Avatar
aishapot
Junior Poster in Training
74 posts since Sep 2011
Reputation Points: -3 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

This is what I did :)

Dim str As String = "Data Source=CAMILLEPC;Initial Catalog=WAIS.mdf;Integrated Security=True"
Dim con As New SqlClient.SqlConnection

con.ConnectionString = str

Dim ms As New IO.MemoryStream()
Dim ms2 As New IO.MemoryStream()
Dim ms3 As New IO.MemoryStream()
Dim ms4 As New IO.MemoryStream()

nsopic.Image.Save(ms, nsopic.Image.RawFormat)
goodmoralpic.Image.Save(ms2, goodmoralpic.Image.RawFormat)
repcardpic.Image.Save(ms3, repcardpic.Image.RawFormat)
torpic.Image.Save(ms4, torpic.Image.RawFormat)

Dim arrimage() As Byte = ms.GetBuffer
Dim arrimage2() As Byte = ms2.GetBuffer
Dim arrimage3() As Byte = ms3.GetBuffer
Dim arrimage4() As Byte = ms4.GetBuffer

Dim cmd As New SqlCommand("insert into store_image_requirements (NSOBirthC,ReportCard,GoodMoral,TOR,NSOBirthCLabel,ReportCardLabel,GoodMoralLabel,TORLabel,Student_No,Surname,First_Name,Middle_Name)values(@picture1,@picture2,@picture3,@picture4, '" & PathNSO.Text & "', '" & PathRC.Text & "', '" & PathGM.Text & "', '" & PathTOR.Text & "', '" & txtstud_no.Text & "', '" & txtsurname.Text & "', '" & txtfirstname.Text & "', '" & txtmiddlename.Text & "')", con)

cmd.Parameters.Add(New SqlParameter("@picture1", SqlDbType.Image)).Value = arrimage
cmd.Parameters.Add(New SqlParameter("@picture2", SqlDbType.Image)).Value = arrimage2
cmd.Parameters.Add(New SqlParameter("@picture3", SqlDbType.Image)).Value = arrimage3
cmd.Parameters.Add(New SqlParameter("@picture4", SqlDbType.Image)).Value = arrimage4

MessageBox.Show("Scanned Requirements Saved!", "Save Digital Requirements", MessageBoxButtons.OK, MessageBoxIcon.Information)

con.Open()
cmd.ExecuteNonQuery()
con.Close()

You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: