asp.net 表单输出:流编写器写入文件与数据库连接
我必须制作一个 ASP.net 表单,并且只需要收集 3 个字段:姓名、生日和电子邮件。
您认为最好将信息写入 csv 或 xml 文件,或者您认为写入 SQL DB 或其他内容然后从那里导出到文件是否值得?
我认为只写入平面文件是最好的,因为无论如何它都需要导出到 csv/xml 文件中,以便可以将其附加到 Excel 文件中。
我会在 C# 提交按钮函数中使用 Streamwriter 或 filestream 之类的东西:
StreamWriter sw = new StreamWriter(filename, true);
sw.WriteLine(string.Concat
( textBox1.Text
, textBox2.Text
, textBox3.Text
, textBox4.Text
, textBox5.Text
, textBox6.Text
, textBox7.Text ));
sw.Close();
我是否忽略了使用 csv 和 StreamWriter 的缺点?就像当文件达到一定大小时会发生任何奇怪的事情吗?
另外,Streamwriter 与 Filestream 相比如何,或者我应该考虑完全不同的方法?
I have to make an ASP.net form and only need to gather 3 fields: name, bday and email.
Do you think it's best to write the info to a csv or xml file, or do you think it's worth it to write to a SQL DB or something and then export from there to a file?
I'm of the opinion that just writing to a flat file is best because it's just going to need to be exported into a csv/xml file anyway so it can be appended to an excel file.
I'd use something like streamwriter or filestream in my C# submitbutton function:
StreamWriter sw = new StreamWriter(filename, true);
sw.WriteLine(string.Concat
( textBox1.Text
, textBox2.Text
, textBox3.Text
, textBox4.Text
, textBox5.Text
, textBox6.Text
, textBox7.Text ));
sw.Close();
Am I overlooking shortcomings of using csv and StreamWriter? Like do any weird things happen when the file gets to a certain size?
Also, how is Streamwriter compared to Filestream, or should I be looking at a different method entirely?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
即使对于小型应用程序,您也永远不会后悔使用数据库。尤其是当它们发生变化/成长时。如果您想存储其他数据,则文本文件很难进行更改。
Web 应用程序的文件访问充其量也具有挑战性。如果您确实使用数据库,我最终会研究 XML/XSD 并使用数据集。
Even for small applications you will never regret using a database. Especially if they ever change / grow. Text files are a lot harder to make a change if you want to store other data.
File access for web applications be challenging at best. If you do use a Database I would ultimately look in to XML/XSD and using Data Sets.