Connecting Tech Pros Worldwide Forums | Help | Site Map

BLOB: Please help me figure out wrong is goin wrong

Newbie
 
Join Date: Jul 2008
Posts: 28
#1: Sep 22 '08
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

Plater's Avatar
Moderator
 
Join Date: Apr 2007
Location: New England
Posts: 7,161
#2: Sep 22 '08

re: BLOB: Please help me figure out wrong is goin wrong


What line throws the exception?
Newbie
 
Join Date: Jul 2008
Posts: 28
#3: Sep 23 '08

re: BLOB: Please help me figure out wrong is goin wrong


Quote:

Originally Posted by Plater

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.
Plater's Avatar
Moderator
 
Join Date: Apr 2007
Location: New England
Posts: 7,161
#4: Sep 23 '08

re: BLOB: Please help me figure out wrong is goin wrong


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?
Newbie
 
Join Date: Jul 2008
Posts: 28
#5: Sep 24 '08

re: BLOB: Please help me figure out wrong is goin wrong


Quote:

Originally Posted by Plater

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
Plater's Avatar
Moderator
 
Join Date: Apr 2007
Location: New England
Posts: 7,161
#6: Sep 24 '08

re: BLOB: Please help me figure out wrong is goin wrong


Well that is a managed exception, so there is more to it then that. Try debugging it?
Reply