将fileStream的内容放在数据集中

时间:2013-03-26 14:48:07

标签: vb.net dataset devexpress filestream

我想读取我从DevExpress的XtrapivotGrid获得的Stream。我可以将它保存在计算机中,但我想要的是将它保存在我的数据集中名为dataset1的表中。 现在,我有那个允许保存目录Temp:。

的代码
Using FS As New IO.FileStream("D:\Temp\qqc.layout", IO.FileMode.Create)
     PivotGridControl1.SaveLayoutToStream(FS)
End Using

Dim read As New System.IO.FileStream("D:\Temp\qqc.layout", IO.FileMode.Open, IO.FileAccess.Read)
DataSet1.LayoutMainRapport.ReadXml(read)
DataSet1.AcceptChanges()
read.Close()

表LayoutMainRapport有3列:

  • ID(INT)
  • 名称(为nvarchar(50))
  • 内容(XML)。

流的输出是xml。

提前感谢!

2 个答案:

答案 0 :(得分:1)

我相信您应该将保存的布局转换为字符串,然后将此字符串保存到数据库中(当然,您可以从数据库字符串值中加载此布局):

Private Function SaveLayoutToString(ByVal dxControl As DevExpressControl) As String
    Using ms As MemoryStream = New MemoryStream()
        dxControl.SaveLayoutToStream(ms)
        Return Convert.ToBase64String(ms.ToArray())
    End Using
End Function
Private Sub RestoreLayoutFromString(ByVal dxControl As DevExpressControl, ByVal layout As String)
    If String.IsNullOrEmpty(layout) Then
        Return
    End If
    Using ms As MemoryStream = New MemoryStream(Convert.FromBase64String(layout))
        dxControl.RestoreLayoutFromStream(ms)
    End Using
End Sub

这里DevExpressControl dxControl是支持保存和加载布局的DevExpress控件(XtraPivotGrid,XtraGrid,XtraLayoutControl等)。

答案 1 :(得分:1)

我只需要保存xml的名称并将其保存到我的数据集中。

    Dim saveDialog As SaveLayout = New SaveLayout
    If saveDialog.ShowDialog() = Windows.Forms.DialogResult.OK Then
        Dim read As New IO.MemoryStream
        PivotGridControl1.SaveLayoutToStream(read)
        read.Position = 0
        Dim lecteur As New IO.StreamReader(read)
        Dim ligne As DataRow = DataSet1.LayoutMainRapport.NewRow()

        ligne("Nom") = saveDialog.txtNom.Text
        ligne("Contenu") = lecteur.ReadToEnd()
        DataSet1.LayoutMainRapport.Rows.Add(ligne)
        LayoutMainRapportTableAdapter.Update(DataSet1)
    End If