All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
对PHP程序中的常见漏洞进行攻击_[PHP教程]
站长推荐:Ajax技术概述与现状应用_[AJAX教程]
Web服务器IIS6的PHP最佳配置方法_php资料_编程技术
LINQ体验(12)——LINQ,to,SQL语句之对象标识和对象加载_[Asp.Net教程]
初学:在PHP网站开发中如何使用cookies?_php资料_编程技术
实例简析SQL嵌套子查询_[SQL Server教程]
新手:什么是PHP?网站开发为什么选择PHP?_php资料_编程技术
SQL Server查询含有单引号的数据_[SQL Server教程]
phpMyAdmin安装配置方法全过程_php资料_编程技术
构建安全的Xml,Web,Service系列
Reading number is top 10 pictures
9.3阅兵全景图8-航空梯队
On the verge of extinction of the beach1
青春清纯美女大集合4
2012 national geographic daily picture8
Chinese paper-cut grilles art appreciation8
徐若瑄展示美丽胸围1
美女
可爱的狗熊们
Discharge accidentally Actresses by the breast1
yy365网站上的美女1
Download software ranking
打鸟视频
功夫熊猫2(下集)
Boxer's Top ten classic battle3
Tram sex maniac 2 (H) rar bag11
Kung fu panda - the secret of the teacher
Unix video tutorial9
Unix video tutorial2
超级战舰
在线棋牌游戏3.05版
Red cliff
aaa published in(发表于) 2013/12/18 7:53:46 Edit(编辑)
Asp.net,将数据库里的记录转换成json_.net资料_编程技术

Asp.net,将数据库里的记录转换成json_.net资料_编程技术

Asp.net 将数据库里的记录转换成json_.net资料_编程技术-你的首页-uuhomepage.com

  在前面我已经写了asp的版本,最近一个项目中正好需要用json来填充下拉框,所以写了一个asp.net的将数据库里的记录转换成json,代码如下:


using System;
  using System.Collections.Generic;
  using System.Text;
  using System.Data;
  using System.Data.SqlClient;
  namespace OTC.Utility
  ...{
  public sealed class JSONHelper
  ...{
  /**////
  /// 获取JSON字符串
  ///
  /// 值
  /// 数据表名
  ///
  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对象就可以了。





添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.