我正在从文本文件中的 SQL 导出表,数据导出正常,但列名没有出现在文本文件中。这是代码:
public static void getfiles()
{
SqlDataReader reader;
string query = "Select * from tTable";
string connStr = ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString;
string strDelimiter = "\"|\"";
string strFilePath = @"path";
StringBuilder sb = new StringBuilder();
using (SqlConnection conn = new SqlConnection(connStr))
{
conn.Open();
using (reader = new SqlCommand(query, conn).ExecuteReader())
{
if (reader.HasRows)
{
Object[] items = new Object[reader.FieldCount];
while (reader.Read())
{
reader.GetValues(items);
foreach (var item in items)
{
sb.Append(item.ToString());
sb.Append(strDelimiter);
}
sb.Append("\n");
}
}
}
conn.Close();
File.WriteAllText(strFilePath, sb.ToString());
}
}
我不知道在这种方法中要进行哪些更改