C#表单保存并加载数据 [英] C# form save and load data

查看:186
本文介绍了C#表单保存并加载数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello Guys,

我试图找出一种将表单数据保存到某个文本文件并从中读取的简单方法,但是......找不到任何有用的东西......希望如此你可以给我这个......这将是非常感谢:



我有一个简单的表格,有10个TetxBoxes。我想要的只是表单中的2个额外按钮。第一个用于将输入的数据保存到某个txt或其他文件中,第二个用于从该文件中读取。



当您填写表格的一半并决定稍后完成时,此功能非常有用。然后你保存它,第二天你加载并从那里继续。我需要从DropDown列表中保存TextBox值和值。



任何资源或评论的链接都将不胜感激。



再次感谢!



Modestas

Hello Guys,
I was trying to find out a simple way of saving form data into some text file and reading from it, but.... could not find anything usefull... hopefully you can give me hand with this... which would be hihly appreciated:

I have a simple form with like 10 TetxBoxes. All I want to have is 2 additional buttons in the form. 1st for saving entered data into some txt or other file and 2nd to read from that file.

This is usefull when you fill half of the form and decide to finish later. Then you save it and next day you load and continue from there. I need to save TextBox values and values from DropDown lists.

Any link to resource or comment would be appreciated.

Thanks a lot again!

Modestas

推荐答案

这实际上非常简单,假设您的文本框都是单行。 (如果它们是多行的,它会变得有点复杂,因为您可能需要将它们转换为带分隔符的单个字符串,并在重新加载时将它们重新分开)



有很多方法可以做到这一点。

1)你可以从文本文件中读取和写入 - 这很简单:只需创建一个StreamWriter并编写每个字符串在另一条线上。然后逐行阅读它们并重置文本框等等。

2)你可以使用应用程序设置 - 再次简单,你在应用程序中添加一个设置然后访问它属性每行的.Settings.Default.MySettingName。如果文件最初不存在,那么优于文本文件可以提供默认值。

3)您可以使用XMLDocument来序列化数据。更复杂,但不是很多。

4)您可以使用一个简单的数据库(可能是SQLCE或SQLite)来存储和重新提供数据。



还有其他解决方案(很多)但这些可能是最简单的解决方案。



这取决于你想要存储的东西,以及你想要的东西是多么健壮/可编辑。



对于一个没有使用文件名的非常简单的解决方案,我可能会选择2。
This is actually pretty simple, assuming that your textboxes are all single line. (If they are multiline, it gets a little more complex as you probably need to convert them to a single string with separators, and split them back up again when you reload them)

There are a load of ways to do this.
1) You could just read and write from a text file - it''s simple to do: just create a StreamWriter and write each string on a separate line. Then read them back line by line and reset you textboxes and so forth.
2) You could use applications settings - again it''s simple, you add a setting in your application then access it vis Properties.Settings.Default.MySettingName for each line. Has the advantage over a text file that you can supply a default if the file is not initially present.
3) You could use an XMLDocument to serialise your data. A little more complex, but not a lot.
4) You could use a simple database (SQLCE or SQLite perhaps) to store and retirve your data.

There are other solutions (lot of them) but those are probably the simplest ones to implement.

It depends on what you want to store really, and how robust / human editable you want things to be.

For a really simple solution that didn''t use file names, I''d probably go with option 2.


引用:

我试图找到一种将表单数据保存到某些内容的简单方法文本文件并从中读取,但....找不到任何有用的东西...

I was trying to find out a simple way of saving form data into some text file and reading from it, but.... could not find anything usefull...



这根本不是真的: Google [ ^ ]


这篇关于C#表单保存并加载数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆