报表速度提升
This commit is contained in:
@ -5,7 +5,9 @@
|
||||
* Website:
|
||||
*********************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Data;
|
||||
using System.Text;
|
||||
|
||||
namespace HT.Cloud.Code
|
||||
{
|
||||
@ -66,5 +68,44 @@ namespace HT.Cloud.Code
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 转换为json字符串
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
///
|
||||
public static string ToJson(this DataTable dt)
|
||||
{
|
||||
StringBuilder jsonString = new StringBuilder();
|
||||
jsonString.Append("[");
|
||||
DataRowCollection drc = dt.Rows;
|
||||
for (int i = 0; i < drc.Count; i++)
|
||||
{
|
||||
jsonString.Append("{");
|
||||
for (int j = 0; j < dt.Columns.Count; j++)
|
||||
{
|
||||
string strKey = dt.Columns[j].ColumnName;
|
||||
string strValue = drc[i][j].ToString();
|
||||
Type type = dt.Columns[j].DataType;
|
||||
jsonString.Append("\"" + strKey + "\":");
|
||||
strValue = String.Format(strValue, type);
|
||||
if (j < dt.Columns.Count - 1)
|
||||
{
|
||||
jsonString.Append(strValue + ",");
|
||||
}
|
||||
else
|
||||
{
|
||||
jsonString.Append(strValue);
|
||||
}
|
||||
}
|
||||
jsonString.Append("},");
|
||||
}
|
||||
if (jsonString.Length > 1)
|
||||
{
|
||||
jsonString.Remove(jsonString.Length - 1, 1);
|
||||
}
|
||||
jsonString.Append("]");
|
||||
return jsonString.ToString();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user