Click here to Skip to main content
15,886,067 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
THE CODE IS TO LOAD IMAGE FROM TABLE "STAFFPICS" AND IS GIVING PROBLEM AT"
PictureBox1.Image = Image.FromStream(stmSTAFF_PICS)
PICS)PICS)" SAYING INVALID PARAMETER.HELP ME OUT

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
       Dim strConnection As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data source=C:\Users\BELLCONSULT\Documents\COUNCILS.mdb"
       Dim cn As OleDb.OleDbConnection = New OleDb.OleDbConnection(strConnection)
       cn.Open()

       Dim dd As New OleDb.OleDbCommand("select STAFF_PICS from STAFFPICS where F_NO =" & Val(TextBox2.Text), cn)
       Dim dr As OleDb.OleDbDataReader = dd.ExecuteReader()
       dr.Read()
       If dr.HasRows Then
           Dim byteSTAFF_PICS(dr.GetBytes(0, 0, Nothing, 0, Integer.MaxValue) - 1) As Byte
           dr.GetBytes(0, 0, byteSTAFF_PICS, 0, byteSTAFF_PICS.Length)
           Dim stmSTAFF_PICS As New IO.MemoryStream(byteSTAFF_PICS)
           PictureBox1.Image = Image.FromStream(stmSTAFF_PICS)

       End If
       dr.Close()

   End Sub
Posted
Updated 24-May-13 8:47am
v2
Comments
OriginalGriff 24-May-13 3:31am    
DON'T SHOUT. Using all capitals is considered shouting on the internet, and rude (using all lower case is considered childish). Use proper capitalisation if you want to be taken seriously.

1 solution

 
Share this answer
 
Comments
adesewa 24-May-13 14:48pm    
i didnt get ur comment pls.
OriginalGriff 24-May-13 15:06pm    
Follow the link.
The chances are you saved the wrong data to your database, so when you try to retrieve the image, you get an error. The link explains what you need to do to fix your save-image code.
adesewa 25-May-13 15:53pm    
i dont understand that i saves wrong data into the database
OriginalGriff 25-May-13 16:25pm    
What code did you use for the save?
[edit] Bloody auto predictive text! 'Coffee' for 'code'[/edit]
adesewa 27-May-13 8:06am    
This code load the picture from system to picturebox on the form:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim OpenFileDialog1 As New OpenFileDialog
With (OpenFileDialog1)
.CheckFileExists = True
.ShowReadOnly = False
.Filter = "All Files|*.*|Bitmap Files (*)|*.bmp;*.gif;*.jpg"
.FilterIndex = 2
If .ShowDialog = Windows.Forms.DialogResult.OK Then
' Load the specified file into a PictureBox control.

PictureBox1.Image = Image.FromFile(.FileName)
If PictureBox1.Image.Width > 100 Or PictureBox1.Image.Height > 100 Then
MessageBox.Show("YOUR PICTURES MUST BE 100 X 100 ")
End If
End If
End With

End Sub


This code is used to save data into STAFFPICS Table
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim ms As New IO.MemoryStream
PictureBox1.Image.Save(ms, PictureBox1.Image.RawFormat)
Dim arrImage() As Byte = ms.GetBuffer

Dim cnString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data source=C:\Users\BELLCONSULT\Documents\COUNCILS.mdb"
Dim cn As OleDb.OleDbConnection = New OleDb.OleDbConnection(cnString)
cn.Open()
Dim SSQL As String = "INSERT into STAFFPICS(F_NO,STAFF_PICS) VALUES('" & TextBox1.Text & "','" & arrImage.ToString & "')"
Dim cmd As OleDb.OleDbCommand = New OleDb.OleDbCommand(SSQL, cn)
cmd.ExecuteNonQuery()
cn.Close()
MessageBox.Show("THANKS")

End Sub

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900