Welcome to Dream.In.Code
Getting VB.NET Help is Easy!

Join 136,355 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 2,679 people online right now. Registration is fast and FREE... Join Now!




Save image to access mdb

 
Reply to this topicStart new topic

Save image to access mdb, Insert image in access mdb.

ericj86
3 Sep, 2008 - 02:48 PM
Post #1

New D.I.C Head
*

Joined: 3 Sep, 2008
Posts: 3

' I get this error code on runtime A first chance exception of type 'System.InvalidOperationException' occurred in System.Data.dll

vb

Imports System
Imports System.IO
Imports System.Data

Public Class SaveImage
Shared Sub main(ByVal iPath As String)

Dim o As System.IO.FileStream
Dim r As StreamReader
Dim gifFile As String

gifFile = iPath

If Dir(gifFile) = "" Then
Console.Write("Invalid File Path")
Exit Sub
End If

o = New FileStream(gifFile, FileMode.Open, FileAccess.Read, FileShare.Read)
r = New StreamReader(o)

Try

Dim FileByteArray(o.Length - 1) As Byte
o.Read(FileByteArray, 0, o.Length)
Dim Con As New System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.3.51;Persist Security Info=False;DataSource=CombatTools.mdb")

Dim Sql As String = "INSERT INTO Ranks (rName,rFilesize,rImage) VALUES (?,?,?)"
Dim Cmd As New System.Data.OleDb.OleDbCommand(Sql, Con)
Cmd.Parameters.Add("@rImage", System.Data.OleDb.OleDbType.Binary, o.Length).Value = FileByteArray
Cmd.Parameters.Add("@rFilesize", System.Data.OleDb.OleDbType.VarChar, 100).Value = o.Length
Cmd.Parameters.Add("@rName", System.Data.OleDb.OleDbType.VarChar, 100).Value = iPath

Con.Open()
Cmd.ExecuteNonQuery()
Con.Close()
Catch ex As Exception
Console.Write(ex.ToString)

End Try
End Sub
End Class


Mod Edit: Please use code tags when posting your code. Code tags are used like so => code.gif

Thanks,
PsychoCoder smile.gif

User is offlineProfile CardPM
+Quote Post

thava
RE: Save Image To Access Mdb
3 Sep, 2008 - 05:14 PM
Post #2

D.I.C Regular
Group Icon

Joined: 17 Apr, 2007
Posts: 442



Thanked: 18 times
Dream Kudos: 50
My Contributions
move this to vb.net
User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: Save Image To Access Mdb
3 Sep, 2008 - 05:31 PM
Post #3

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 8,984



Thanked: 125 times
Dream Kudos: 8625
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
What line does it say the error occurs on?

Also, since this is VB.NET code I'm moving it to the VB.NET Forum smile.gif
User is online!Profile CardPM
+Quote Post

ericj86
RE: Save Image To Access Mdb
3 Sep, 2008 - 08:00 PM
Post #4

New D.I.C Head
*

Joined: 3 Sep, 2008
Posts: 3

QUOTE(PsychoCoder @ 3 Sep, 2008 - 06:31 PM) *

What line does it say the error occurs on?

Also, since this is VB.NET code I'm moving it to the VB.NET Forum smile.gif



it dont say a line, it says everytime I click the test button "Button2"
which then executes that code.


User is offlineProfile CardPM
+Quote Post

Damage
RE: Save Image To Access Mdb
3 Sep, 2008 - 08:19 PM
Post #5

D.I.C Addict
Group Icon

Joined: 5 Jun, 2008
Posts: 738



Thanked: 7 times
Dream Kudos: 75
My Contributions
If you run commands or call methods of the SqlCommand or OleDbCommand object, you'll get the error if a connection is not open
User is offlineProfile CardPM
+Quote Post

dineeshd
RE: Save Image To Access Mdb
4 Sep, 2008 - 04:16 AM
Post #6

D.I.C Addict
Group Icon

Joined: 30 Jun, 2008
Posts: 578



Thanked: 16 times
Dream Kudos: 575
My Contributions
Try commenting or removing the TRY CATCH statement and run the code you will be able to know which line is throwing the error and you can see a more specific error message.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 09:08AM

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month