如何将文本框的内容附加到csv文件中?

问题描述:

我有2个文本框,如何在这两个文本框中键入内容,信息将附加到csv文件中?

谢谢

I have 2 textboxes, and how can I type something in those two textboxes and info will append to csv file?

Thanks

您必须在这里做几件事:

1.获取这些文本框的文本.有两个变量可以做到.
2.学习打开文件...查找"fopen,fwrite" ...您会发现如何轻松使用文件.
3.将内容写入文件:
3.1.如果您知道格式,而且也知道没人会手动修改文件,那么一切真的很简单...只需在文件末尾添加所需的文本即可.
3.2.如果不能确定没有人会修改这些文件...那么现在是时候创建一个解析器并验证文件的完整性,然后再向其中插入文本了...

这些是如何做到的粗糙步骤...

通常,在编程时,您必须划分所面临的问题...

至少这是我要做的...

希望这对您有帮助...

使用这些指令...当您发现问题时(肯定会),请回发,这里的人将为您提供帮助.

祝你好运!
You have to do several things here:

1. Get the text of those textboxes. Two variables will do it.
2. Learn to open a file... look for "fopen, fwrite"... you''ll find how to work with files easily.
3. Writing the contents to the file:
3.1. If you know the format and also know that nobody will modify the file by hand, then everything is really easy... simply add the text you want at the end of the file...
3.2. If you can''t be sure that nobody will modify those files... well then it''s time to create a parser and verify the integrity of the file before inserting text into it...

Those are the rough steps on how to do it...

Usually when programming you must divide the problem you are facing...

At least this is what I''d do...

Hope this helps...

With those directives... when you will find a problem (surely you will) please post back and someone here will help you.

Good luck!


这是我的代码:


私有无效AddBtn_Click(对象发送者,EventArgs e)
{
//创建CSV文件
字符串CSV_File ="C:\\ test.csv";

System.IO.StreamWriter(CSV_File,true);
如果(System.IO.File.Exists(CSV_File))
{
字符串FileHeader =(名字" +," +姓氏" + System.Environment.NewLine);
System.IO.File.WriteAllText(CSV_File,FileHeader);
}
字符串FileDeail = FirstTxt.Text +," + LastTxt.Text;
System.IO.File.AppendAllText(CSV_File,FileDeail);
FirstTxt.Text =";
LastTxt.Text =";
{

但是,当我在文本框中输入新信息时,旧信息将被删除.

如何在旧信息之后附加新信息?

谢谢,
Here is my code:


private void AddBtn_Click(object sender, EventArgs e)
{
//create CSV file
string CSV_File = "C:\\test.csv";

System.IO.StreamWriter(CSV_File, true);
if (System.IO.File.Exists(CSV_File))
{
string FileHeader = ("First Name" + "," + "Last Name" + System.Environment.NewLine);
System.IO.File.WriteAllText(CSV_File, FileHeader);
}
string FileDeail = FirstTxt.Text + "," + LastTxt.Text;
System.IO.File.AppendAllText(CSV_File, FileDeail);
FirstTxt.Text = " ";
LastTxt.Text = " ";
{

However, when i type a new info into textboxes, the old information is deleted.

How to append the new info after the old info?

thanks,