使用savefiledialog将数据集转换为txt文件 [英] dataset to txt file using savefiledialog
问题描述
我正在网上上课并且我的导师没有帮助。我希望有人能指引我朝着正确的方向前进。我创建了一个由表单运行的groceryapp。基本上,用户将输入杂货商品并将其存储在变量
名称"购物篮"中。所以现在我需要将变量数据存储到txt文件中。我无法弄清楚如何保存变量。 showfiledialog是工作文件。非常感谢任何帮助!
I am taking an intro class online and my instructor is not helpful. I am hoping someone here can guide me in the right direction. I created a groceryapp that is run by a form. Basically the user will enter a grocery item and it is stored in a variable names "basket". So now I need to store the variable data into a txt file. I cannot figure out how to save the variable. The showfiledialog is working file. Any help is much appreciated!
Private Sub SaveApplicationToolStrip_Click(sender As Object, e As EventArgs) Handles SaveApplicationToolStrip.Click
'Set the save dialog properties
With saveDialog
.DefaultExt = "txt"
.FileName = "GroceryList"
.Filter = "Text Documents (*txt)|*.txt|All Files(*.*|*.*"
.OverwritePrompt = True
.FilterIndex = 1
.Title = "Save Basket Items"
End With
If saveDialog.ShowDialog() = DialogResult.OK Then
Try
strFileName = saveDialog.FileName
My.Computer.FileSystem.WriteAllText(strFileName, basket, False)
Catch ex As Exception
MessageBox.Show(ex.Message, My.Application.Info.Title,
MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End If
推荐答案
您似乎误解了什么是对话框。对话框用于与用户进行通信。在这种情况下,文件对话框可以知道文件名是什么usere想要和必须保存的地方。它不是保存实际的文件。
You seems to misunderstand what is a dialog. A dialog is for communication with the user. In this case of the file dialog to know what filename the usere wants and where it has to be saved. It is not saving an actual file.
您想要保存的是另一个问题。如果它来自数据集,则必须指出哪些数据。数据集是数据表的包装器,它包含对象行。将它放在文本文件中并不常见。我认为没有人可以帮助你。
What you want to save is another problem. If it is from a dataset you have to point what data. A dataset is a wrapper around datatable which holds rows of objects. It is not a normal way to put that in a textfile. I don't think nobody can help you with that.
这就像是否有人可以帮助你把埃菲尔铁塔放在它的位置。这似乎很容易,但事实并非如此。因此,不要责怪你的导师。
It is as asking if somebody can help you to put the Eiffel tower on its point. It seems easy but it is not. Therefore don't blame your instructor.
这篇关于使用savefiledialog将数据集转换为txt文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!