|
Is it possible to read an image file from a database (SQL Server 2000 in my case) and pass directly into an ImageList control without creating any bitmap files in a system folder?
With my current code(see below), the image is read from the database and then stored as a bitmap file under a windows folder titled "Tickmarks." Then, as needed, the various pictureboxes are referenced to the appropriate file in the Tickmarks folder. However, I don't want the bitmap files exposed to (and possibly manipulated by) the application's user. Any ideas?
Dim objSQLConn As New SqlClient.SqlConnection(gstrConnString) Dim objSQLCmd As New SqlClient.SqlCommand() Dim drSQLDataReader As SqlClient.SqlDataReader Dim objrow As Data.DataRow Dim strBitmapPath As String, strFileName As String Dim imgBitmap() As Byte Dim lngBitmapSize As Long Dim objDirInfo As New IO.DirectoryInfo(gstrApplicationPath & "\Tickmarks\") Dim objFileInfo() As IO.FileSystemInfo Dim objFileItem As IO.FileSystemInfo
//'assign path to bitmap files strBitmapPath = gstrApplicationPath & "\Tickmarks\"
//'Assign the connection to the command objSQLCmd.CommandType = CommandType.StoredProcedure objSQLCmd.Connection = objSQLConn objSQLConn.Open()
//'Populate the grid with the firm-wide reserved TM's objSQLCmd.Parameters.Add("@Reserved", True) objSQLCmd.CommandText = "1CommonTMGetList" drSQLDataReader = objSQLCmd.ExecuteReader
While (drSQLDataReader.Read()) ......//'Populate the tblTMAll table ......objrow = tblTMAll.NewRow ......objrow("TmID") = drSQLDataReader.Item("TmID") ......objrow("FileName") = drSQLDataReader.Item("FileName") ......objrow("LongDesc") = drSQLDataReader.Item("LongDesc") ......objrow("ShortDesc") = drSQLDataReader.Item("ShortDesc") ......tblTMAll.Rows.Add(objrow) ......//'Create bitmap and each record and place in "Tickmark" folder (if not already existant in folder)) ......strFileName = drSQLDataReader.Item("FileName") ......objFileInfo = objDirInfo.GetFileSystemInfos() ......//'Iterate through the Tickmark folder to see whether the current record's file name already exists as a bitmap ......For Each objFileItem In objFileInfo ...........If objFileItem.Attributes <> IO.FileAttributes.Directory And objFileItem.Name = strFileName Then ................If objFileItem.Extension = ".bmp" Then ......................imgBitmap = drSQLDataReader.Item("Symbol") ......................lngBitmapSize = UBound(imgBitmap) ......................Dim fsBitmap As New IO.FileStream(strBitmapPath & strFileName & ".bmp", IO.FileMode.OpenOrCreate, IO.FileAccess.Write) ......................fsBitmap.Write(imgBitmap, 0, lngBitmapSize) ......................fsBitmap.Close() ................End If ...........End If ......Next End While
drSQLDataReader.Close() objSQLConn.Close() |