system.IO.MemoryStream -> Save to Sql server?

  • Thread starter Thread starter Chris Thunell
  • Start date Start date
C

Chris Thunell

I have a memory stream that i would like to save to an sql2000 database and
then retreave it later on. I currently have the field set as an sql2000 ->
VarBinary type of field. Any suggestions in vb.net??? When i run the
current code i get an: "An unhandled exception of type
'System.InvalidCastException' occurred in system.data.dll - Additional
information: Object must implement IConvertible" error.

Dim Str As New System.IO.MemoryStream

GridView1.SaveLayoutToStream(Str)

Str.Seek(0, System.IO.SeekOrigin.Begin)

Dim myRow As DataRow

Me.daPGMGridViews.Fill(Me.DataSet11.tblPgmGridViews)

If Me.DataSet11.tblPgmGridViews.Rows.Count = 0 Then

myRow = Me.DataSet11.tblPgmGridViews.NewRow

myRow("GridViewBinary") = Str

Me.DataSet11.tblPgmGridViews.Rows.Add(myRow)

Else

myRow = Me.DataSet11.tblPgmGridViews.Rows(0)

myRow("GridViewBinary") = Str

End If

Me.daPGMGridViews.Update(Me.DataSet11.tblPgmGridViews)

Thanks for your help!
Chris Thunell
(e-mail address removed)
 
Chris,

Normally is it the image type that holds a byte array.

I hope this helps,

Cor
 
Chris Thunell said:
I have a memory stream that i would like to save to an sql2000 database
and then retreave it later on. I currently have the field set as an
sql2000 -> VarBinary type of field. Any suggestions in vb.net??? When i
run the current code i get an: "An unhandled exception of type
'System.InvalidCastException' occurred in system.data.dll - Additional
information: Object must implement IConvertible" error.
[...]
myRow("GridViewBinary") = Str

Try 'Str.ToArray()'. This method will convert the data in the stream to a
byte array.
 
In access database, I use the following parameter setting to save byte arrays
to which a memory stream can be converted where dat.frontcover is the byte
array of any file like a bitmap, jpeg, etc.

P = New OleDb.OleDbParameter("@FrontCoverPicture",
OleDb.OleDbType.LongVarBinary, Dat.FrontCover.Length,
ParameterDirection.Input, False, 0, 0, Nothing, DataRowVersion.Current,
Dat.FrontCover)
 
Back
Top