将存储的过程数据转换为CSV。我试图弄清楚如何使用空的逗号和报价
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
替换此段:
随之而来的是:
但是您将在专用的CSV库中更好地做 ,其中Nuget上有几种不错的选择。
此外,如果您使用的是
StringBuilder
,因为您听说它更快,请记住,更快的是相对的。StringBuilder
的速度比此类工作的字符串串联要快,但是如果您最终要写入网络流,文件或Web响应Replace this segement:
with this:
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 aStreamWriter