首页新闻找找看学习计划

ASP.NET从mongodb查数据

0
悬赏园豆:5 [已解决问题] 解决于 2013-09-13 11:03

运行出现错误:

输入字符串的格式不正确。

说明: 执行当前 Web 请求期间,出现未经处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。

异常详细信息: System.FormatException: 输入字符串的格式不正确。

源错误:

行 99:             else
行 100:            {
行 101:                list.AddRange(cursor.ToList());
行 102:            }
行 103:            return list;

DAL层

/// <summary>
        /// 把MongoCursor转换成List类型
        /// </summary>
        /// <param name="cursor">文档游标</param>
        /// <param name="preprocess">预处理方法</param>
        /// <returns></returns>
        protected internal List<TDocument> CursorToList(MongoCursor<TDocument> cursor, PreprocessHandler<TDocument> preprocess)
        {
            List<TDocument> list = new List<TDocument>(30);
            bool isPreprocess = preprocess != null;
            if (isPreprocess)
            {
                foreach (TDocument document in cursor)
                {
                    var doc = document;
                        preprocess(ref doc);
                    list.Add(doc);
                }
            }
            else
            {
                list.AddRange(cursor.ToList());
            }
            return list;
        }
        #endregion
#region 根据query查询集合
/// <summary>
/// 根据query查询集合
/// </summary>
/// <param name="query">条件</param>
/// <param name="cursorSettings">查询参数</param>
/// <param name="preprocess">预处理方法</param>
/// <returns></returns>
public List<TDocument> Find(IMongoQuery query, MongoCursorSettings cursorSettings, PreprocessHandler<TDocument> preprocess)
{
var list = new List<TDocument>();
Execute(delegate(MongoCollection<TDocument> mongoCollection)
{
var cursor = mongoCollection.Find(query);
if (cursorSettings != null)
{
cursorSettings.Set(cursor);
}
list = CursorToList(cursor, preprocess);
});
return list;

}
#endregion

BLL层

public string UserSelectList(string fields,string greps)
        {
            userage = new DAL_UserAgeManager();
            QueryDocument query = new QueryDocument();
            query.Add(fields, greps);
            List<Model_User> list = userage.Find(query, null, null);
            string strlist = userage.ListToDataTable(list).ToJson();
            return strlist;
        }

UI层

string a = userage.UserSelectList("address","大庆");
                Response.Write(a);
denyscolar的主页 denyscolar | 初学一级 | 园豆:6
提问于:2013-09-09 14:02
< >
分享
最佳答案
0

给query方法加一个游标参数

denyscolar | 初学一级 |园豆:6 | 2013-09-09 15:24
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册