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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Chris Thunell

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


    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.Invalid CastException' occurred in system.data.dll - Additional
    information: Object must implement IConvertible" error.

    Dim Str As New System.IO.Memor yStream

    GridView1.SaveL ayoutToStream(S tr)

    Str.Seek(0, System.IO.SeekO rigin.Begin)

    Dim myRow As DataRow

    Me.daPGMGridVie ws.Fill(Me.Data Set11.tblPgmGri dViews)

    If Me.DataSet11.tb lPgmGridViews.R ows.Count = 0 Then

    myRow = Me.DataSet11.tb lPgmGridViews.N ewRow

    myRow("GridView Binary") = Str

    Me.DataSet11.tb lPgmGridViews.R ows.Add(myRow)

    Else

    myRow = Me.DataSet11.tb lPgmGridViews.R ows(0)

    myRow("GridView Binary") = Str

    End If

    Me.daPGMGridVie ws.Update(Me.Da taSet11.tblPgmG ridViews)

    Thanks for your help!
    Chris Thunell
    cthunell@pierce associates.com


  • Cor Ligthert [MVP]

    #2
    Re: system.IO.Memor yStream -> Save to Sql server?

    Chris,

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

    I hope this helps,

    Cor


    Comment

    • Herfried K. Wagner [MVP]

      #3
      Re: system.IO.Memor yStream -> Save to Sql server?

      "Chris Thunell" <cthunell@pierc eassociates.com > schrieb:[color=blue]
      > 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.Invalid CastException' occurred in system.data.dll - Additional
      > information: Object must implement IConvertible" error.
      >[...]
      > myRow("GridView Binary") = Str[/color]

      Try 'Str.ToArray()' . This method will convert the data in the stream to a
      byte array.

      --
      M S Herfried K. Wagner
      M V P <URL:http://dotnet.mvps.org/>
      V B <URL:http://classicvb.org/petition/>

      Comment

      • Cor Ligthert [MVP]

        #4
        Re: system.IO.Memor yStream -&gt; Save to Sql server?

        Chriss,

        Have a look at this sample.



        I hope this helps,

        Cor


        Comment

        • Dennis

          #5
          Re: system.IO.Memor yStream -&gt; Save to Sql server?

          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.OleDbPara meter("@FrontCo verPicture",
          OleDb.OleDbType .LongVarBinary, Dat.FrontCover. Length,
          ParameterDirect ion.Input, False, 0, 0, Nothing, DataRowVersion. Current,
          Dat.FrontCover)
          --
          Dennis in Houston


          "Cor Ligthert [MVP]" wrote:
          [color=blue]
          > Chriss,
          >
          > Have a look at this sample.
          >
          > http://www.windowsformsdatagridhelp....6-38b5a2f7fdf0
          >
          > I hope this helps,
          >
          > Cor
          >
          >
          >[/color]

          Comment

          Working...