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

simonyong

Member
Joined
Aug 27, 2008
Messages
12
Programming Experience
Beginner
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:
VB.NET:
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 a moderator:
Top Bottom