嘿伙计们,我有这么快的代码,我无法弄清楚如何停止导出标题行。
结果
PrimaryRowGuid|Text | blah blah blahg blah blah blah blahg blahblah blah blahg blah blah blah blahg blah
我需要结果:
blah blah blahg blah blah blah blahg blahblah blah blahg blah blah blah blahg blah
任何帮助都是适当的!
using (StreamWriter writer = new StreamWriter(strm))
{
SqlCommand cmd = new SqlCommand(sql, con);
SqlDataReader reader = cmd.ExecuteReader();
for (int i = 0; i < reader.FieldCount; i++)
writer.Write((i == 0 ? "" : "|") + reader.GetName(i));
writer.Write("\n");
while (reader.Read())
{
for (int i = 1; i < reader.FieldCount; i++)
writer.Write((i == 0 ? "" : "|") + reader[i].ToString().Replace(@"<swme> ", string.Empty).Replace(@" </swme>|", "|").Replace(@" </swme>", ";").Replace('\r', ' ').TrimEnd((char)';'));
writer.WriteLine();
}
reader.Close();
答案 0 :(得分:7)
标题行由以下代码行导出:
for (int i = 0; i < reader.FieldCount; i++)
writer.Write((i == 0 ? "" : "|") + reader.GetName(i));
writer.Write("\n");
我假设您可以从这里弄清楚如何摆脱它。
答案 1 :(得分:1)
取出阅读器。阅读代码块,你会没事的
答案 2 :(得分:0)
for (int i = 0; i < reader.FieldCount; i++)
writer.Write((i == 0 ? "" : "|") + reader.GetName(i));
writer.Write("\n");
删除该区块。