L
lgbjr
Hi All,
As you know, I've made the switch from Access/Jet to MSDE 2K. And I'm now
encountering my first little problem. I have some pictureboxes that display
images from the DB. For each picturebox, I have some buttons (Add/Change
Image, Rotate Image, Delete Image) and a context menu (Copy/Paste, Open,
Edit, and Preview). For open, Edit, and Preview, I'm creating a temporary
file on disk, then writing the file back to the DB and deleting it once the
user is finished with it. this is how I'm creating the temp file:
Dim conn As OLEDBConnection = New OLEDBConnection
conn.ConnectionString = XConn.ConnectionString
If conn.State <> ConnectionState.Open Then
conn.Open()
End If
Dim cmd As OLEDBCommand = New OLEDBCommand(sql, conn)
Dim fs As FileStream
Dim bw As BinaryWriter
Dim bufferSize As Integer = 300000
Dim outbyte(300000 - 1) As Byte
Dim retval As Long
Dim startIndex As Long = 0
Try
Dim reader As OLEDBDataReader =
cmd.ExecuteReader(CommandBehavior.SequentialAccess)
reader.Read()
fs = New FileStream(pbfile, FileMode.OpenOrCreate,
FileAccess.Write)
bw = New BinaryWriter(fs)
startIndex = 0
retval = reader.GetBytes(0, 0, outbyte, 0, bufferSize)
bw.Write(outbyte)
bw.Flush()
bw.Close()
fs.Close()
reader.Close()
If conn.State = ConnectionState.Open Then
conn.Close()
conn.Dispose()
End If
When I was using OLE to connect to the JetDB:
If a user pasted an image into a picturebox, then immediately tried to open,
edit, or preview it, an exception was thrown by the OLEDBDataReader,
because, since an update wasn't done after the paste, the image didn't exist
in the DB. I was catching this exception and telling the user that the image
had to be saved before any further actions could be taken with the image.
Upon switching to MSDE 2K:
I switched from using the OLEDBDataReader to using the SQLDataReader (Just
replace the OLEDB stuff above with SQL stuff). Under the same circumstances,
an exception is not thrown. I just get an empty temp file.
What I don't know is this: is it a difference in the reader or in the DB? My
guess is that it's a difference in the DBs, specifically something to do
with how an empty cell is represented. Using Jet, the empty cell was
represented with a DBNull, which caused the reader to throw an exception.
Does an SQL DB use DBNull? If not, any ideas on how to fix this?
TIA
Lee
As you know, I've made the switch from Access/Jet to MSDE 2K. And I'm now
encountering my first little problem. I have some pictureboxes that display
images from the DB. For each picturebox, I have some buttons (Add/Change
Image, Rotate Image, Delete Image) and a context menu (Copy/Paste, Open,
Edit, and Preview). For open, Edit, and Preview, I'm creating a temporary
file on disk, then writing the file back to the DB and deleting it once the
user is finished with it. this is how I'm creating the temp file:
Dim conn As OLEDBConnection = New OLEDBConnection
conn.ConnectionString = XConn.ConnectionString
If conn.State <> ConnectionState.Open Then
conn.Open()
End If
Dim cmd As OLEDBCommand = New OLEDBCommand(sql, conn)
Dim fs As FileStream
Dim bw As BinaryWriter
Dim bufferSize As Integer = 300000
Dim outbyte(300000 - 1) As Byte
Dim retval As Long
Dim startIndex As Long = 0
Try
Dim reader As OLEDBDataReader =
cmd.ExecuteReader(CommandBehavior.SequentialAccess)
reader.Read()
fs = New FileStream(pbfile, FileMode.OpenOrCreate,
FileAccess.Write)
bw = New BinaryWriter(fs)
startIndex = 0
retval = reader.GetBytes(0, 0, outbyte, 0, bufferSize)
bw.Write(outbyte)
bw.Flush()
bw.Close()
fs.Close()
reader.Close()
If conn.State = ConnectionState.Open Then
conn.Close()
conn.Dispose()
End If
When I was using OLE to connect to the JetDB:
If a user pasted an image into a picturebox, then immediately tried to open,
edit, or preview it, an exception was thrown by the OLEDBDataReader,
because, since an update wasn't done after the paste, the image didn't exist
in the DB. I was catching this exception and telling the user that the image
had to be saved before any further actions could be taken with the image.
Upon switching to MSDE 2K:
I switched from using the OLEDBDataReader to using the SQLDataReader (Just
replace the OLEDB stuff above with SQL stuff). Under the same circumstances,
an exception is not thrown. I just get an empty temp file.
What I don't know is this: is it a difference in the reader or in the DB? My
guess is that it's a difference in the DBs, specifically something to do
with how an empty cell is represented. Using Jet, the empty cell was
represented with a DBNull, which caused the reader to throw an exception.
Does an SQL DB use DBNull? If not, any ideas on how to fix this?
TIA
Lee