473,513 Members | 2,263 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

BLOB: Please help me figure out wrong is goin wrong

28 New Member
I'm newbie to .net and currently learning to use BLOB to insert image into database
What i'm facing is i dont know what is going wrong to make me continue getting this error:
An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in system.data.dll

Hope to get some direction from all senior

the following is my code:
__________________________________________________ _____________
Expand|Select|Wrap|Line Numbers
  1. Private Function OpenConn() As Boolean
  2.         myCN = New OleDb.OleDbConnection 
  3.         Dim sConnString = "Provider=MSDAORA.1;User ID=123;Password=123;Data Source=test" '
  4.         myCN.ConnectionString = sConnString
  5.         myCN.Open()
  6.         OpenConn = True
  7.  
  8.     End Function
  9. ________________________________________________________________
  10.     Private Sub CloseConn()
  11.         If myCN.State = ConnectionState.Open Then
  12.             myCN.Close()
  13.         End If
  14.     End Sub
  15. _________________________________________________________________
  16.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  17.         Dim openDlg As OpenFileDialog = New OpenFileDialog
  18.         openDlg.Filter = "All Files|*.*|Bitmaps|*.bmp|GIFs|*.gif|JPEGs|*.jpg"
  19.         Dim filter As String = openDlg.Filter
  20.         openDlg.Title = "Open a Bitmap File"
  21.         If (openDlg.ShowDialog() = DialogResult.OK) Then
  22.             curFileName = openDlg.FileName
  23.             TextBox1.Text = curFileName
  24.             With PictureBox1
  25.                 .Image = Image.FromFile(openDlg.FileName)
  26.                 .SizeMode = PictureBoxSizeMode.CenterImage
  27.  
  28.             End With
  29.  
  30.         End If
  31.     End Sub
  32. ________________________________________________________________
  33.     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  34.  
  35.         OpenConn()
  36.  
  37.         Dim cmd As OleDbCommand
  38.         Dim fs As FileStream
  39.  
  40.         fs = New FileStream(curFileName, FileMode.Open, FileAccess.Read) ' Read a bitmap contents in a stream
  41.         Dim b(fs.Length - 1) As Byte
  42.         fs.Read(b, 0, b.Length)
  43.         fs.Close()
  44.  
  45.         cmd = New OleDbCommand("INSERT INTO test (filename, filesave) Values ('" + TextBox1.Text.Substring(TextBox1.Text.LastIndexOf("\") + 1+ "','?')", myCN)
  46.         cmd.Parameters.Add("filesave", OleDbType.VarBinary)  
  47.         cmd.Parameters.Item(0).Value() = b  
  48.         cmd.ExecuteNonQuery()
  49.         CloseConn()
  50.  
  51.         MsgBox("New Record inserted.")
  52.         End
  53.     End Sub
  54. __________________________________________________________________
I'm thinking is it my last few line (SqlCommand) going wrong?
but don't know how to modify it
Please give me some direction, thanks in advance
** im using microsoft visual studio .net 2003 and 1.1 framework
Sep 22 '08 #1
5 1544
Plater
7,872 Recognized Expert Expert
What line throws the exception?
Sep 22 '08 #2
simonyong
28 New Member
What line throws the exception?



hello, Plater

the line throws the exception is :
cmd.ExecuteNonQuery()

so i think it may caused by the incorrect command text
Thanks.
Sep 23 '08 #3
Plater
7,872 Recognized Expert Expert
Yes, I don't believe your command paramaters and sql string are correct.
The exception message should have had more details about WHAT it didn't like?
Sep 23 '08 #4
simonyong
28 New Member
Yes, I don't believe your command paramaters and sql string are correct.
The exception message should have had more details about WHAT it didn't like?

there are just displayed :
An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in system.data.dll
Sep 24 '08 #5
Plater
7,872 Recognized Expert Expert
Well that is a managed exception, so there is more to it then that. Try debugging it?
Sep 24 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

3
21897
by: Thierry | last post by:
Hello, I do have a mysql database with a BLOB column. What is the proprest way to read this column ? Thx, Thierry
1
5627
by: sams | last post by:
Iam posting this after trying many tutorials in the NG and failing to retrieve the blob out of a record. So please bear with me before before you pull the water hose or flame throwers ...... I...
3
3130
by: NotGiven | last post by:
I am researching the best place to put pictures. I have heard form both sides and I'd like to know why one is better than the other. Many thanks!
3
10427
by: adam | last post by:
Hi, I have an issue that i just cant seem to figure out hope some one can help. right i am getting people to input the own images directly into a blob within a mysql database. then on the next...
0
3405
by: Corrine | last post by:
I am trying to pass a temporary BLOB that I've created in Java, to a PLSQL function that modifies it, and then to retrieve this modified value back to Java, all using JDBC. I can't figure out...
4
2233
by: Ellen K | last post by:
Hi all, It was my understanding (Please correct me if I'm wrong on this!) that BLOB data actually reside on their own separate pages and a BLOB field only holds a pointer to the location of the...
9
7962
by: matt | last post by:
hello, im doing my first ASP.NET app that inserts & retrieves files from Oracle (no need for a discussion on *that*!). i learned first-hand of the somewhat awkward technique for inserting...
4
4211
by: skunapareddy | last post by:
I am needing to read a blob from database and pass it to another java program. I researched internet and found a program that reads a file on the client pc and gives bytes, but when I modified the...
16
6641
by: wizard | last post by:
Here is a piece of code below for writing and reading blobs in SQLITE database. I ' ve a problem to read from blob struct called 'Points' Any help would be appreciated Reagards Greg ...
0
7265
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7388
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7547
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7541
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5693
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5098
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4751
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3240
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3230
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.