【freesql】使用Ado执行sql语句查询结果集时参数化举例

 

复制代码
StringBuilder sb = new StringBuilder();
sb.Append("select a.id,a.stationid,a.stationname,a.stationdesc,a.keycode,");
sb.Append("b.address,b.area,b.city,b.establishtime,b.installedcapacity,b.installedpower,b.latitude,b.longitude,");
sb.Append("left join enery_storage_station c on a.stationid = c.stationid ");
sb.Append(" where 1=1 ");
if (!string.IsNullOrWhiteSpace(name))
{
sb.AppendFormat(" and a.stationname like '%{0}%'",@name);
}
return _repository.GetIFreeSql().Ado.Query<StationsInfoModel>(sb.ToString(), new SqlParameter { ParameterName = "@name", Value = name });
复制代码

 

posted @   狼窝窝  阅读(993)  评论(2编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?
点击右上角即可分享
微信分享提示