亚洲免费乱码视频,日韩 欧美 国产 动漫 一区,97在线观看免费视频播国产,中文字幕亚洲图片

      1. <legend id="ppnor"></legend>

      2. 
        
        <sup id="ppnor"><input id="ppnor"></input></sup>
        <s id="ppnor"></s>

        2017年計算機三級數(shù)據(jù)庫知識:數(shù)據(jù)庫里的記錄與json之間的轉(zhuǎn)換

        字號:

          數(shù)據(jù)庫里的記錄與json之間轉(zhuǎn)換。代碼如下:
            


            

        using System; 
        using System.Collections.Generic; 
        using System.Text; 
        using System.Data; 
        using System.Data.SqlClient; 
        namespace OTC.Utility 
        ...{ 
        public sealed class JSONHelper 
        ...{ 
        /**//// 
        /// 獲取JSON字符串 
        /// 
        /// 值 
        /// 數(shù)據(jù)表名 
        /// 
        public static string GetJSON(SqlDataReader drValue, string strTableName) 
        ...{ 
        StringBuilder sb = new StringBuilder(); 
        sb.AppendLine("{"); 
        sb.AppendLine(" " + strTableName + ":{"); 
        sb.AppendLine(" records:["); 
        try 
        ...{ 
        while (drValue.Read()) 
        ...{ 
        sb.Append(" {"); 
        for (int i = 0; i < drValue.FieldCount; i++) 
        ...{ 
        sb.AppendFormat(""{0}":"{1}",", drValue.GetName(i), drValue.GetValue(i)); 
        } 
        sb.Remove(sb.ToString().LastIndexOf(’,’), 1); 
        sb.AppendLine("},"); 
        } 
        sb.Remove(sb.ToString().LastIndexOf(’,’), 1); 
        } 
        catch(Exception ex) 
        ...{ 
        throw new Exception(ex.Message); 
        } 
        finally 
        ...{ 
        drValue.Close(); 
        } 
        sb.AppendLine(" ]"); 
        sb.AppendLine(" }"); 
        sb.AppendLine(" };"); 
        return sb.ToString(); 
        } 
        } 
        }

        接下來你只需要傳一個SqlDataReader對象就可以了。