i had a problem with this codes.. this codes will retrieve image from database that will based on the employeenumber.

 Dim CN As New OleDbConnection(cnString)
        CN.Open()
        daImage = New OleDbDataAdapter()
        daImage.SelectCommand = New OleDbCommand("SELECT * FROM EmployeeProfile ", CN)
        dsImage = New DataSet("dsImage")

        Dim dataTable As DataTable = dsImage.Tables(0)

        If IDPicturePB.Image IsNot Nothing Then

            IDPicturePB.Image.Dispose()
        End If

        Dim fsImage As New FileStream("image.jpg", FileMode.Create)

        For Each dataRow As DataRow In dataTable.Rows
            If dataRow(0).ToString() = EmployeeNumberIDTB.Text.ToString() Then

                Dim blob As Byte() = DirectCast(dataRow(1), Byte())

                fsImage.Write(blob, 0, blob.Length)
                fsImage.Close()
                fsImage = Nothing

                IDPicturePB.Image = Image.FromFile("image.jpg")
                IDPicturePB.SizeMode = PictureBoxSizeMode.StretchImage
                IDPicturePB.Refresh()
            End If
        Next

error in this line : Dim dataTable As DataTable = dsImage.Tables(0)
can someone explain it to me? :(
error is Cannot find table 0.

Recommended Answers

All 4 Replies

You didn't say what the error message is but where in your code did you create a NEW datatable like:

Dim dataTable As NEW DataTable = dsImage.Tables(0)

no. i just want to retrieve image from the database.

Sorry, my mistake....you need to add the table that you apparently want to name 'dataTable'. Try this

        Dim dsimage = New DataSet("dsImages")
        dsimage.Tables.Add("dataTable")

        MsgBox(dsimage.Tables.Count)

        MsgBox(dsimage.Tables(0).TableName)

Why are you doing select * from if you only need Image from DB? and also check for the data after Dim dataTable As DataTable = dsImage.Tables(0).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.