scot63 Posted October 6, 2003 Posted October 6, 2003 (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 October 6, 2003 by scot63 Quote
*Experts* jfackler Posted October 7, 2003 *Experts* Posted October 7, 2003 Scot, Try a search on this forum for that "Additional information" quote. It's a common error message, I think you'll get your answer. Jon Quote
scot63 Posted October 15, 2003 Author Posted October 15, 2003 (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 October 15, 2003 by scot63 Quote
loyal Posted October 15, 2003 Posted October 15, 2003 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 Quote Gary Says: To be a good programmer, you must be good at debugging
scot63 Posted October 16, 2003 Author Posted October 16, 2003 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 Quote
loyal Posted October 16, 2003 Posted October 16, 2003 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 :D2ways.zip Quote Gary Says: To be a good programmer, you must be good at debugging
scot63 Posted October 16, 2003 Author Posted October 16, 2003 Loyal, Thanks so much for the examples! I'm sure you have more important things to do then help me. I really appreciate it! Scot Quote
loyal Posted October 16, 2003 Posted October 16, 2003 you welcome my friend anytime Quote Gary Says: To be a good programmer, you must be good at debugging
scot63 Posted October 21, 2003 Author Posted October 21, 2003 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 Quote
loyal Posted October 22, 2003 Posted October 22, 2003 Hi you are asking about viewing an image from access's form right ? if so here's an exmaple I have done it before good luck :)embededimages.zip Quote Gary Says: To be a good programmer, you must be good at debugging
guerven Posted October 11, 2004 Posted October 11, 2004 Yoi! Can I save a drawingpath to an image. Sorry if I posted it here. dunno how to post a new thread. Thanks! Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.