将datagridview保存到文本文件 [英] save datagridview to a textfile
问题描述
我有2个datagridviews
在工作时都有一个非常大的数据,大约70,000 +行,每个datagridview有3列
现在我必须用我自己的扩展名将datagridview保存到单个文件中
所以当用户简单双击我的自定义扩展名的文件时,我的form1被打开,数据再次填充到datagridview
现在我已经创建了这样的代码,我正在添加单行并将其写入文本文件
它适用于少量行,但随着行增加时间也会增加。
为70,000行它大约10分钟,现在用户可以不等到10分钟
有什么方法可以让它快速?
i have 2 datagridviews
while working both have a very large data about 70,000 + rows with 3 columns in each datagridview
now i have to save both datagridview to a single file with my own extension
so when user simple double clicks a file with my custom extension , my form1 is opened and data is filled to both datagridview again
now i have created such code where i am tacking single rows and writing it to the textfile
it is good for small number of rows but as lines added time is also increased .
for 70,000 lines it tacks about 10 mins , now user can not wait until 10 mins
is there any way to make it fast ?
推荐答案
假设你有与DataGrdiView关联的DataSet或DataTable,您只需使用 Da taSet.WriteXml [ ^ ]写下这个地段。如果每个DGV都基于DataTable,则创建一个新的DataSet,添加两个表,然后编写DataSet。然后,您可以使用 DataSet.ReadXml [ ^ ]并恢复两个tables。
Assuming you have a DataSet or DataTable associated with the DataGrdiView, you could just use DataSet.WriteXml[^] to write the lot. If each DGV is based on a DataTable, then create a new DataSet, add both tables, and write the DataSet. You can then read it back with DataSet.ReadXml[^] and restore the two tables.
抱歉,但是两个datagridviews都没有绑定
还有不仅要将datagridview保存在文件中,除此之外2 datagridview u =我还要保存2个richtextbox文本和一些变量值
所以我想要的是
当用户关闭应用程序时整个项目保存在一个文件中,以便用户可以加载项目文件,应用程序必须从最后一次开始。
sorry but both datagridviews are unbound
also there is not only datagridview to be saved in file , addition to this 2 datagridview u=i also have to save 2 richtextbox text and some variable values
so what i want is
when user closes application the whole project is saved in a file , so that user can load project file and application must start from where it was last left .
这篇关于将datagridview保存到文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!