使用C#窗体表单将文本写入文本文件 [英] write text to a textfile using C# windows forms
问题描述
我想创建包含列的文本文件
column1 column2 column3
我想要第1列中的数据从gridview column1和grid2中恢复从gridview column2中恢复。
如果记录存在,我想要第3列中的数据然后已经存在,否则保存成功。
例如:
column1 column2 column3
01已经存在
02 B成功保存
我使用的是Windowsforms&.NET FRamework 2.0。
任何人都可以帮我解决这个问题。
I want to create textfile having columns
column1 column2 column3
I want data in column1 is retrived from gridview column1 & column2 is retrived from gridview column2.
I want data in column3 if record exists then already exists otherwise Saved Successfully.
eg:
column1 column2 column3
01 A already exists
02 B Saved Successfully
I am using Windowsforms & .NET FRamework 2.0.
Can any one help me to solve this problem.
推荐答案
请参考以下Link
首先,请阅读我对该问题的评论。
其次,按照上一个问题的答案并尝试做点什么!
这样的事情会是这样的:
First of all, please read my comment to the question.
Secondly, follow the anwers to your previous question and try to do something!
It would be something like this:
using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"C:\MyData.txt"))
{
foreach (DataGridViewRow row in DataGridView1.Rows)
{
file.WriteLine(String.Format("{0} {1} {2}", row[0], row[1], row[2]));
}
}
注意:未经测试!
如需了解更多信息,请参阅:字符串.Format方法 [ ^ ]
这篇关于使用C#窗体表单将文本写入文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!