Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
C# / VB.NET - immagini da vb.net 2010 e access 2007
Forum - C# / VB.NET - immagini da vb.net 2010 e access 2007

Avatar
berto_baffo (Normal User)
Newbie


Messaggi: 2
Iscritto: 11/09/2012

Segnala al moderatore
Postato alle 13:58
Martedì, 11/09/2012
carissimi
il mio probblema è che non riesco a trasferire una immagine da access 2007 a un picturebox su una form in visual basic 2010
e fare il contrario
con questo codice l'immagine e memorizzata su access in Byte e recuperata in Byte
Codice sorgente - presumibilmente VB.NET

  1. Private Sub retrieve_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles retrieve.Click
  2.  
  3.         Dim conn As New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=n:\rino\Databaseimage.accdb;Persist Security Info=False;")
  4.         conn.Open()
  5.  
  6.         Dim str As String = "select * from Images where imageName = '1'"
  7.         Dim cmd As New OleDb.OleDbCommand(str, conn)
  8.         Dim adapter As New System.Data.OleDb.OleDbDataAdapter(cmd)
  9.         Dim dt As New DataTable
  10.         Try
  11.             adapter.Fill(dt)
  12.         Catch ex As OleDb.OleDbException
  13.             MessageBox.Show(ex.Message, "OleDbException")
  14.             Exit Sub
  15.         Catch ex As Exception
  16.             MessageBox.Show(ex.Message, "GeneralException")
  17.             Exit Sub
  18.         End Try
  19.         conn.Close()
  20.  
  21.         'Byte [] per l'immagine
  22.  
  23.         If dt.Rows.Count > 0 Then
  24.             Dim bArray As Byte() = CType(dt.Rows(0).Item("image"), Byte())
  25.             If bArray.Length > 0 Then
  26.                 Dim stream As IO.MemoryStream = New IO.MemoryStream(bArray)
  27.                 PictureBox1.Image = Image.FromStream(stream)
  28.                 stream.Close()
  29.             End If
  30.         End If
  31.  
  32.  
  33.  
  34.     End Sub
  35.  
  36.     Function oleDBCmd() As Object
  37.         Throw New NotImplementedException
  38.     End Function
  39.  
  40.     Private Function connectString() As String
  41.         Throw New NotImplementedException
  42.     End Function
  43.  
  44.  
  45.     Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
  46.  
  47.     End Sub
  48.  
  49.     'Tu sai che questo è solo il codice di esempio che ti ha detto come fare questo, si sono sicuramente non poteva farlo funzionare solo se si copia e incolla.
  50.     '
  51.     'sta utilizzando OLEDB? Prova per favore:'
  52.     Private Sub AddImage_Click1(sender As Object, e As System.EventArgs) Handles AddImage.Click
  53.         'Image to byte[]      
  54.         Dim myImage As Image = Image.FromFile("n:\rino\foto\no.jpg")
  55.         Dim imgMemoryStream As IO.MemoryStream = New IO.MemoryStream()
  56.         myImage.Save(imgMemoryStream, System.Drawing.Imaging.ImageFormat.Jpeg)
  57.         Dim imgByteData As Byte() = imgMemoryStream.GetBuffer()
  58.  
  59.         'Inserire l'immagine nel database
  60.  
  61.         Dim conn As New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=n:\rino\Databaseimage.accdb;Persist Security Info=False;")
  62.         conn.Open()
  63.         Dim str As String = "insert into Images ([imageName] ,[image]) values (1,@myimage)"
  64.         Dim cmd As New OleDb.OleDbCommand(str, conn)
  65.         cmd.Parameters.Add("@myimage", OleDb.OleDbType.Binary).Value = imgByteData
  66.  
  67.         Try
  68.             cmd.ExecuteNonQuery()
  69.         Catch ex As OleDb.OleDbException
  70.             MessageBox.Show(ex.Message, "OleDbException")
  71.             'MessageBox.Show(ex.InnerException.Message)
  72.             Exit Sub
  73.         Catch ex As Exception
  74.             MessageBox.Show(ex.Message, "GeneralException")
  75.             Exit Sub
  76.         End Try
  77.         conn.Close()
  78.     End Sub
  79.  
  80.  
  81.  
  82.  
  83. End Class


come posso fare lo stesso lavoro ma in bipmap image.
grazie per la vostra disponuibilità
roberto

PM Quote