把datatable 输出为表格
我想把datatable 转换成文本, 然后调用邮件类, 发给 相关的邮箱内, 原先的转换如下
DataTable dt = ds.Tables[0];
foreach (DataColumn c in dt.Columns)//输出标题
{
sendstr += c.ColumnName + "\t";//输出列名
}
sendstr = sendstr + "\r\n";
//输出datatable 的内容
int cols = dt.Columns.Count;//列数
int rows = dt.Rows.Count;
for (int w = 0; w < rows; w++)
{
for (int j = 0; j < cols; j++)
{
//遍历每一行每一列;
sendstr += dt.Rows[w][j].ToString() + "\t";
if (j == cols - 1) //列索引为最后一列;
{
sendstr += "\r\n";//列的最后一位加上换行符
}
}
}
发到邮箱里,只是一行一行的字符,不是表格,于是我做以下转换
string sendstr = @"<table border="1"> <tr>";
但是报错了,老是提示应输入; 我觉得加了@应该是没有问题的,请大神指示,谢谢