Dim ado As ADO = New ADO() ado.strSQL = "Select keyID, imgText From zTestRichText Where keyID = 1" ado.RetrieveData(ado.objDS, "MyImages") Dim myRow As DataRow myRow = ado.objDS.Tables("MyImages").Rows(0) Dim MyData() As Byte MyData = myRow("imgText") Dim K As Long K = UBound(MyData) Dim ms As New MemoryStream(K - 1) ms.Write(MyData, 0, K) ' Error occurs on Next Line :Additional information: Offset and ' length were out of bounds for the array or count is greater than ' the number of elements from index to the end of the source ' collection. Me.rtfTest.LoadFile(ms, RichTextBoxStreamType.RichText) ms.Close() ms = Nothing ado = Nothing MsgBox("Load Complete")Here is the save code, this works.
Dim ms As New MemoryStream() Me.rtfTest.SaveFile(ms, RichTextBoxStreamType.RichText) Dim ba(ms.Length) As Byte ms.Read(ba, 0, ms.Length) ms.Close() ms = Nothing Dim ado As New ADO() ado.strSQL = "Select keyID, imgText From zTestRichText Where keyID = 1" ado.CreateAdapter() ado.UseCommandBuilder() ado.CreateDataSet() ado.OpenConnection() ado.objDA.Fill(ado.objDS, "MyImages") ' A primary key must be set to use the command builder object to update tables. '********* Dim dt As DataTable = ado.objDS.Tables("MyImages") Dim pk As DataColumn = dt.Columns("keyID") dt.PrimaryKey = New DataColumn() {pk} '********** ' End setting up a primary on the dataset. ado.objDS.Tables("MyImages").Rows(0).Item("imgText") = ba ado.objDA.Update(ado.objDS, "MyImages") ado.CloseConnection() ado = Nothing MsgBox("Save Complete")