• 全部
  • VBS
  • .NET技术
  • VBA
  • VB网络编程
  • VB多媒体
  • VB数据库
  • VB控件
  • VB COM/DCOM
  • VB基础类
  • VB API
  • 问答

请问如何将已经查询的DataGrid的数据保存成文件

xmjcwo 2003-10-28 10:52:06
我用了saveFileDialog控件请问如何实现,或者有其他办法,请教大家,谢谢!
...全文
3 点赞 收藏 5
写回复
5 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
AreZong 2003-10-28
这涉及数据集的序列化问题.
请参考下面代码(仅供参考):

Private Sub SerializeDataSet(filename As String)
Dim ser As XmlSerializer = new XmlSerializer(GetType(DataSet))
' Create a DataSet add a Table, coumn, and ten rows.
Dim ds As DataSet = new DataSet("myDataSet")
Dim t As DataTable = new DataTable("table1")
Dim c As DataColumn = new DataColumn("thing")
t.Columns.Add(c)
ds.Tables.Add(t)
Dim r As DataRow
Dim i As Integer
for i = 0 to 10
r = t.NewRow()
r(0) = "Thing " & i
t.Rows.Add(r)
Next
Dim writer As TextWriter = new StreamWriter(filename)
ser.Serialize(writer, ds)
writer.Close()
End Sub
回复
xmjcwo 2003-10-28
随便啊,txt,html都可以
回复
ETstudio 2003-10-28
你要保存成什么文件??
回复
xmjcwo 2003-10-28
我试着这样做
Sub Save()
Dim i As Integer
Dim j As Integer
SaveFileDialog1.Filter = "Text Files|*.txt|All Files|*.*"
If SaveFileDialog1.ShowDialog = DialogResult.OK Then
Dim FS As FileStream = SaveFileDialog1.OpenFile
Dim SW As New StreamWriter(FS)
For i = 0 To i = ds.Tables(0).Rows.Count
For j = 0 To j = ds.Tables(0).Columns.Count

'SaveFileDialog1.FilterIndex = i

SW.WriteLine(DataGrid1.Item(i, j))

Next

Next
SW.Close()
FS.Close()

End If
但是只能输出第一行第一列,请大家帮忙要在哪里改进才能全部输出
回复
xmjcwo 2003-10-28
用saveFileDialog控件如何实现?
回复
发帖
VB
创建于2007-09-28

1.6w+

社区成员

VB技术相关讨论,主要为经典vb,即VB6.0
申请成为版主
帖子事件
创建了帖子
2003-10-28 10:52
社区公告
暂无公告