将存储的过程数据转换为CSV。我试图弄清楚如何使用空的逗号和报价

发布于 2025-02-10 01:33:26 字数 705 浏览 1 评论 0原文

sb.AppendLine("Employee Id,First Name,Last Name,Email,Username,Password,Role,Group Name,Country Code, Supervisor Id, Hire Date, Birth Date");

for (int i = 0; i < dt.Rows.Count; i++)
{
    String[] empid = dt.Rows[i]["EmpId"].ToString().Split(new Char[] { '-' });
    sb.AppendLine(Convert.ToInt32(empid[0]).ToString("000000") + "," + dt.Rows[i]["FirstName"] + "," + dt.Rows[i]["LastName"].ToString().Replace(",", " ") +
         ",," + dt.Rows[i]["Email"] + ",reward," + dt.Rows[i]["Role"] + ",CCCC," + ",," + ",," + dt.Rows[i]["EmployeeHireDate"] + "," + dt.Rows[i]["EmployeeBirthDate"]);
}
  • 电子邮件字段需要是空的
  • 用户名,需要是电子邮件
  • 国家代码是空的
  • 主管ID。
sb.AppendLine("Employee Id,First Name,Last Name,Email,Username,Password,Role,Group Name,Country Code, Supervisor Id, Hire Date, Birth Date");

for (int i = 0; i < dt.Rows.Count; i++)
{
    String[] empid = dt.Rows[i]["EmpId"].ToString().Split(new Char[] { '-' });
    sb.AppendLine(Convert.ToInt32(empid[0]).ToString("000000") + "," + dt.Rows[i]["FirstName"] + "," + dt.Rows[i]["LastName"].ToString().Replace(",", " ") +
         ",," + dt.Rows[i]["Email"] + ",reward," + dt.Rows[i]["Role"] + ",CCCC," + ",," + ",," + dt.Rows[i]["EmployeeHireDate"] + "," + dt.Rows[i]["EmployeeBirthDate"]);
}
  • email field needs to be empty
  • username needs to be the email
  • country code needs to be empty
  • supervisor id needs to be empty

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

请爱~陌生人 2025-02-17 01:33:26

替换此段:

+ ",CCCC," + ",," + ",," +

随之而来的是:

+ ",CCCC,,," + 

但是您将在专用的CSV库中更好地做 ,其中Nuget上有几种不错的选择。

此外,如果您使用的是StringBuilder,因为您听说它更快,请记住,更快的是相对的。 StringBuilder的速度比此类工作的字符串串联要快,但是如果您最终要写入网络流,文件或Web响应

Replace this segement:

+ ",CCCC," + ",," + ",," +

with this:

+ ",CCCC,,," + 

But you'll really do MUCH better with a dedicated csv library, of which there are several good options on NuGet.

Additionally, if you're using StringBuilder because you heard it's faster, remember that faster is relative. StringBuilder is faster than string concatenation for this kind of work, but if you're ultimately going to writing to a network stream, file, or web response you'll do even better using a StreamWriter

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文