BLOB: Please help me figure out wrong is goin wrong

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • simonyong
    New Member
    • Jul 2008
    • 28

    BLOB: Please help me figure out wrong is goin wrong

    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.Ol eDb.OleDbExcept ion' occurred in system.data.dll

    Hope to get some direction from all senior

    the following is my code:
    _______________ _______________ _______________ _______________ ___
    Code:
    Private Function OpenConn() As Boolean
            myCN = New OleDb.OleDbConnection 
            Dim sConnString = "Provider=MSDAORA.1;User ID=123;Password=123;Data Source=test" '
            myCN.ConnectionString = sConnString
            myCN.Open()
            OpenConn = True
    
        End Function
    ________________________________________________________________
        Private Sub CloseConn()
            If myCN.State = ConnectionState.Open Then
                myCN.Close()
            End If
        End Sub
    _________________________________________________________________
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim openDlg As OpenFileDialog = New OpenFileDialog
            openDlg.Filter = "All Files|*.*|Bitmaps|*.bmp|GIFs|*.gif|JPEGs|*.jpg"
            Dim filter As String = openDlg.Filter
            openDlg.Title = "Open a Bitmap File"
            If (openDlg.ShowDialog() = DialogResult.OK) Then
                curFileName = openDlg.FileName
                TextBox1.Text = curFileName
                With PictureBox1
                    .Image = Image.FromFile(openDlg.FileName)
                    .SizeMode = PictureBoxSizeMode.CenterImage
    
                End With
    
            End If
        End Sub
    ________________________________________________________________
        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    
            OpenConn()
    
            Dim cmd As OleDbCommand
            Dim fs As FileStream
    
            fs = New FileStream(curFileName, FileMode.Open, FileAccess.Read) ' Read a bitmap contents in a stream
            Dim b(fs.Length - 1) As Byte
            fs.Read(b, 0, b.Length)
            fs.Close()
    
            cmd = New OleDbCommand("INSERT INTO test (filename, filesave) Values ('" + TextBox1.Text.Substring(TextBox1.Text.LastIndexOf("\") + 1+ "','?')", myCN)
            cmd.Parameters.Add("filesave", OleDbType.VarBinary)  
            cmd.Parameters.Item(0).Value() = b  
            cmd.ExecuteNonQuery()
            CloseConn()
    
            MsgBox("New Record inserted.")
            End
        End Sub
    __________________________________________________________________
    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
    Last edited by kenobewan; Sep 22 '08, 01:09 PM. Reason: Use code tags
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    What line throws the exception?

    Comment

    • simonyong
      New Member
      • Jul 2008
      • 28

      #3
      Originally posted by Plater
      What line throws the exception?



      hello, Plater

      the line throws the exception is :
      cmd.ExecuteNonQ uery()

      so i think it may caused by the incorrect command text
      Thanks.

      Comment

      • Plater
        Recognized Expert Expert
        • Apr 2007
        • 7872

        #4
        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?

        Comment

        • simonyong
          New Member
          • Jul 2008
          • 28

          #5
          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.Ol eDb.OleDbExcept ion' occurred in system.data.dll

          Comment

          • Plater
            Recognized Expert Expert
            • Apr 2007
            • 7872

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

            Comment

            Working...