Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

Hello All,

 

Is it possible to take an image, from a picture box in vb.net and store the image in an access field? I'd also like the ability to view the image, frrom a form/report within access.

 

I found an example that uses SQL in the "101 visual basic .net applications" book, but i'm not sure if it's possible with access.

 

I've already made the connection to the table. The table contains an OLE field, is this the proper field type to use?

 

i've tried the following...

 

ds_Repair.Tables("qryMarkup").Rows(int_ThisRec).Item(2) = pb_View.Image

adap_Repair.Update(ds_Repair, "qryMarkup")

 

ds_Repair is the dataset

qryMarkup is the query inside access

.Row(int_ThisRec) is the current row

.item(2) is one of two OLE fields in the access table

pb_View is the picture box

adap_Repair is the adapter

 

i get the following error...

 

An unhandled exception of type 'System.InvalidOperationException' occurred in system.data.dll

 

Additional information: Update requires a valid UpdateCommand when passed DataRow collection with modified rows.

 

 

 

Any help would be appreciated.

 

Scot

Edited by scot63
  • 2 weeks later...
Posted (edited)

Jon,

 

thanks for the tip. I can now successfully update a text field in an existing record of an access database. However, i still need the ability to (a) update a field with an image from a picture box and (b) store it in a format that lets me view it in access too, via a form.

 

I have a book "VB.net for MS Access Databases" and it appears that the stream class is used to read/write to OLE fields in access. But this book does not give any examples.

 

I have another book "101 vb.net applications" that does contain an example of saving an image, but it's to an SQL db, not an access db.

 

does anyone know how to do this or point me in the proper direction?

 

thanks,

 

scot

Edited by scot63
Posted

hi

 

here's an Example how to Save An Image into Access Data Base

 

it's the same example that found in 101 but with little deff

 

like VarBinary for Saving Image to Access Data base

 


Private Sub SavingImage()
       Dim ms As New MemoryStream
       picBox.Image.Save(ms, picBox.Image.RawFormat)
       Dim image() As Byte = ms.GetBuffer
       ms.Close()
       Try


' lblFilePath with hold the pic name for example hi.gif
           Dim Fn() As String = _
           Split(lblFilePath.Text, "\")
           fn.Reverse(fn)

           Dim oleS As String = _
   ("INSERT INTO pictures(Picture)" & _
   "VALUES(?)")
           Dim cmd As New OleDbCommand(oleS, CnnMain)
           With cmd
               
               .Parameters.Add(New OleDbParameter("@Picture", _
           OleDbType.VarBinary)).Value = image
               
           End With


           CnnMain.Open()
           cmd.ExecuteNonQuery()
           CnnMain.Close()
       Catch ex As Exception
           MsgBox(ex.Message)
           Exit Sub
       End Try
   End Sub

 

 

To Read an Image from Access Data base

 

here's an exmaple

 

 


'Keep this var at the top of form   Global VAR

Public RP As Integer 'ReadingPicture Variable 

Protected Sub ReadImages()
       Try

           RP = CType(Me.BindingContext(DsMain1, "Main").Position, Integer)
           Dim arrPicture() As Byte = _
            CType(DsMain1.Tables("pictures").Rows(RP)("Picture"), _
            Byte())
           Dim ms As New MemoryStream(arrPicture)
           picBox.Image = Image.FromStream(ms)
           lblFilePath.Text = _
            DsMain1.Tables("pictures").Rows(RP)("FileName").ToString
       Catch ex As Exception
          
       End Try
   End Sub

 

now for reading image for Each employee for example

 

just call the method ReadImages()

 

I hope it help

 

bye

Gary Says: To be a good programmer, you must be good at debugging
Posted

Loyal,

 

thanks! your code did the trick. I'm able to fill the ole (image) field in my access database with "long binary data". But when i use a form, in access to view the field, i dont see the image.

 

Is it possible to see the image from within Access - or is it just storing the data for retreival from my vb.net app.

 

My goal is to also see the image from within access. Is there some parameter that i have to set in the form or field to get the image to appear in access?

 

thanks for your help.

 

Scot

Posted

Hi

 

it's so easy to View the Image just Supply a name of the image

 

I made 2 Exmple for you 1 is for Embedded Images to Access Data

 

and 2 for Linked the image to DataBase

 

if any question I'd be so ready for :D

2ways.zip

Gary Says: To be a good programmer, you must be good at debugging
Posted

Loyal,

 

Currently, the field, in the MS Access table contains the phrase "long binary data".

 

I need to view, the saved image, in Microsoft Access. Is this possible? If possible, i'd like to see the image, on a form in access.

 

I have a current workaround. Instead of saving the image to the table, i save the path and filename to the table. In access, during an update event I display the image based on the path and filename. It works, but it's not the ideal method.

 

Again,

 

any help would be appreciated.

 

Scot

  • 11 months later...
  • 7 years later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...