zoukankan      html  css  js  c++  java
  • C#查询datatable接收数据集并转换为json返回

     StringBuilder commandText = new StringBuilder();
    commandText.Append("select clientcode,coperator, skdate,usefund,skway,skprice from ReceiptLog");
    commandText.Append(" WHERE clientcode = '"+Custcode+"'");
    SysDBModel.CodeValue Codeobj = new SysDBModel.CodeValue();
    DataTable CodeTable = new DataTable();
    Codeobj.ExecuteQuery(commandText.ToString(), CodeTable);
    var jsonString = new StringBuilder();
    if (CodeTable.Rows.Count > 0)
    {
        jsonString.Append("[");
        for (int i = 0; i < CodeTable.Rows.Count; i++)
        {
            jsonString.Append("{");
            for (int j = 0; j < CodeTable.Columns.Count; j++)
            {
                if (j < CodeTable.Columns.Count - 1)
                {
                    jsonString.Append(""" + CodeTable.Columns[j].ColumnName.ToString()
                    + "":" + """
                    + CodeTable.Rows[i][j].ToString() + "",");
                }
                else if (j == CodeTable.Columns.Count - 1)
                {
                    jsonString.Append(""" + CodeTable.Columns[j].ColumnName.ToString()
                    + "":" + """
                    + CodeTable.Rows[i][j].ToString() + """);
                }
            }
            if (i == CodeTable.Rows.Count - 1)
            {
                jsonString.Append("}");
            }
            else
            {
                jsonString.Append("},");
            }
        }
        jsonString.Append("]");
    }
    return jsonString.ToString();
    return "OK";

  • 相关阅读:
    shell编程系列5--数学运算
    qperf测量网络带宽和延迟
    使用gprof对应用程序做性能评测
    [转]极不和谐的 fork 多线程程序
    Emacs显示光标在哪个函数
    Iterm2的一些好用法
    [转]最佳日志实践
    Deep Introduction to Go Interfaces.
    CGo中传递多维数组给C函数
    seaweedfs 源码笔记(一)
  • 原文地址:https://www.cnblogs.com/zhipeng007/p/10614965.html
Copyright © 2011-2022 走看看