11/09/12 11:58
berto_baffo
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
come posso fare lo stesso lavoro ma in bipmap image.
grazie per la vostra disponuibilità
roberto
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
Private Sub retrieve_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles retrieve.Click Dim conn As New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=n:\rino\Databaseimage.accdb;Persist Security Info=False;") conn.Open() Dim str As String = "select * from Images where imageName = '1'" Dim cmd As New OleDb.OleDbCommand(str, conn) Dim adapter As New System.Data.OleDb.OleDbDataAdapter(cmd) Dim dt As New DataTable Try adapter.Fill(dt) Catch ex As OleDb.OleDbException MessageBox.Show(ex.Message, "OleDbException") Exit Sub Catch ex As Exception MessageBox.Show(ex.Message, "GeneralException") Exit Sub End Try conn.Close() 'Byte [] per l'immagine If dt.Rows.Count > 0 Then Dim bArray As Byte() = CType(dt.Rows(0).Item("image"), Byte()) If bArray.Length > 0 Then Dim stream As IO.MemoryStream = New IO.MemoryStream(bArray) PictureBox1.Image = Image.FromStream(stream) stream.Close() End If End If End Sub Function oleDBCmd() As Object Throw New NotImplementedException End Function Private Function connectString() As String Throw New NotImplementedException End Function Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load End Sub '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. ' 'sta utilizzando OLEDB? Prova per favore:' Private Sub AddImage_Click1(sender As Object, e As System.EventArgs) Handles AddImage.Click 'Image to byte[] Dim myImage As Image = Image.FromFile("n:\rino\foto\no.jpg") Dim imgMemoryStream As IO.MemoryStream = New IO.MemoryStream() myImage.Save(imgMemoryStream, System.Drawing.Imaging.ImageFormat.Jpeg) Dim imgByteData As Byte() = imgMemoryStream.GetBuffer() 'Inserire l'immagine nel database Dim conn As New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=n:\rino\Databaseimage.accdb;Persist Security Info=False;") conn.Open() Dim str As String = "insert into Images ([imageName] ,[image]) values (1,@myimage)" Dim cmd As New OleDb.OleDbCommand(str, conn) cmd.Parameters.Add("@myimage", OleDb.OleDbType.Binary).Value = imgByteData Try cmd.ExecuteNonQuery() Catch ex As OleDb.OleDbException MessageBox.Show(ex.Message, "OleDbException") 'MessageBox.Show(ex.InnerException.Message) Exit Sub Catch ex As Exception MessageBox.Show(ex.Message, "GeneralException") Exit Sub End Try conn.Close() End Sub End Class
come posso fare lo stesso lavoro ma in bipmap image.
grazie per la vostra disponuibilità
roberto
aaa