当前位置: 首页 > news >正文

网站怎样做的/长沙seo优化排名

网站怎样做的,长沙seo优化排名,成免费的crmdsm,软件开发公司企业MySQL通过实例化对象参数如何查询数据发布时间:2020-06-05 09:56:31来源:PHP中文网阅读:201作者:三月下文主要给大家带来MySQL通过实例化对象参数如何查询数据 ,希望这些内容能够带给大家实际用处,这也是我…

MySQL通过实例化对象参数如何查询数据

发布时间:2020-06-05 09:56:31

来源:PHP中文网

阅读:201

作者:三月

下文主要给大家带来MySQL通过实例化对象参数如何查询数据 ,希望这些内容能够带给大家实际用处,这也是我编辑MySQL通过实例化对象参数如何查询数据 这篇文章的主要目的。好了,废话不多说,大家直接看下文吧。public static string QueryByEntity(T t) where T : new()

{ string resultstr = string.Empty;

MySqlDataReader reader = null; try

{

Type type = typeof(T);

PropertyInfo[] properties = type.GetProperties(); string select = string.Format("Select * from {0} {1}", type.Name, "{0}"); string where = string.Empty; foreach (PropertyInfo property in properties)

{ var value = t.GetPropertyValue(property); if (value != null && !value.Equals(property.GetDefaultValue()))

{ if (string.IsNullOrEmpty(where))

{ where = string.Format(" where {0}='{1}' ", property.Name, value);

} else

{ where = string.Format(" {0} and {1} = '{2}' ", where, property.Name, value);

}

}

} select = string.Format(select, where);

MySqlConnection connection = OpenConnection(); if (connection == null) return resultstr;

MySqlCommand _sqlCom = new MySqlCommand(select, connection);

reader = _sqlCom.ExecuteReader();

List tList = new List(); while (reader.Read())

{

T t1 = new T(); foreach (PropertyInfo property in properties)

{ if (!string.IsNullOrEmpty(reader[property.Name].ToString()))

{

property.SetMethod.Invoke(t1, new object[] { reader[property.Name] });

}

}

tList.Add(t1);

}

resultstr = JsonConvert.SerializeObject(tList);

} catch (Exception ex)

{

Logging.Error(string.Format("查询数据库失败,{0}", ex.Message));

} finally

{ if (reader != null)

{

reader.Close();

reader.Dispose();

}

} return resultstr;

}internal static class ObjectExtend

{ public static object GetPropertyValue(this object obj, PropertyInfo property)

{

Type type = typeof(T);

PropertyInfo propertyInfo = type.GetProperty(property.Name); if (propertyInfo != null)

{ return propertyInfo.GetMethod.Invoke(obj, null);

} return null;

} public static object GetDefaultValue(this PropertyInfo property)

{ return property.PropertyType.IsValueType ? Activator.CreateInstance(property.PropertyType) : null;

}

}

通过实例化参数,对属性赋值,将对象作为参数传入,反射获取对象名称,列名,列值。要求对象名与表名一致,属性与列名一致。

对于以上关于MySQL通过实例化对象参数如何查询数据 ,大家是不是觉得非常有帮助。如果需要了解更多内容,请继续关注我们的行业资讯,相信你会喜欢上这些内容的。

http://www.lbrq.cn/news/1035703.html

相关文章:

  • 像素点建网站/免费推广seo
  • 移动公司营销网站设计/西安优化网站公司
  • 官网建设公司/免费seo提交工具
  • 做微商推广有哪些好的分类信息网站/国外推广网站有什么
  • 微信如何做微商城网站/樱桃磁力bt天堂
  • 邢台开发区建设小学官方网站/中文搜索引擎大全
  • 个人网站做电商/做个公司网站多少钱
  • 企业做网站建设/免费网站推广网站破解版
  • 同ip下网站/一个新公众号怎么吸粉
  • 如何做拼多多商城官网站/自媒体视频发布平台
  • mui做的h5网站案例/自媒体引流推广
  • 网站怎么做seo排名/卢镇seo网站优化排名
  • 中医网站开发/seo技巧
  • 舟山网站建设有限公司/南京今天重大新闻事件
  • 虚拟体验网站/关键词优化快排
  • 制作app需要学哪些知识/武汉seo首页优化技巧
  • 网站做三屏合一/b站新人视频怎么推广
  • 去视频网站做编辑器/外贸怎么找客户资源
  • cc域名做网站好吗/网站搜索引擎推广
  • 提供商城网站制作/百度指数的基本功能
  • 农产品销售网站建设方案/宁波seo教程推广平台
  • 天津 企业网站建设/北京网络营销招聘
  • 做付费视频网站/百度关键词排名查询
  • 电影网站建设公司/保定seo排名优化
  • 新手学做网站下载/汕头网页搜索排名提升
  • seo如何根据网站数据做报表/开一个免费网站
  • 洛阳做网站汉狮网络/爱站seo工具包下载
  • 域名卖给别人有风险吗/seo刷词工具在线
  • 如何查找网站竞争对手的宣传方式/今日头条权重查询
  • 外包小程序公司/seo排名优化表格工具
  • VUE基础笔记
  • 嵌入式系统学习Day17(文件编程-库函数调用)
  • Android 项目:画图白板APP开发(一)——曲线优化、颜色、粗细、透明度
  • 安卓主题定制实践:17.45MB轻量级主题引擎技术解析
  • archlinux中VLC无法播放视频的解决办法
  • 《飞算Java AI:从安装到需求转实战项目详细教学》