First of all, you have to use parameterized queries, instead of concatenated string, because your code is
SQL Injection[
^] vulnerable
If you would like only image, i'd do that this way:
Dim sDbPath As String = Application.StartupPath & "\mochis.mdb"
Dim sConn As String = String.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Persist Security Info=False;", sDbPath)
Dim ms As MemoryStream = New MemoryStream()
Dim sSql As String = "SELECT image FROM catalogo WHERE codigo=@codigo"
Using oConn As OleDbConnection = New OleDbConnection(sConn)
oConn.Open()
Using oComm As OleDbCommand = New OleDbCommand(sSql, oConn)
oComm.Parameters.Add("@codigo", OleDbType.VarChar).Value = TextBox1.Text;
Dim imagedata As Byte() = oComm.ExecuteScalar()
ms.Write(imagedata, 0, imagedata.Length)
Me.PictureBox1.Image = Image.FromStream(ms)
oComm.Dispose()
End Using
oConn.Close()
oConn.Dispose()
End Using
Note: to be able to use this code, you have to install
MS Access database 2010 driver[
^]
For further details about connection, please see:
Access connection strings - ConnectionStrings.com[
^]
Good luck!