From 329e55db60273ae7583a2cd3fda0ba8eb4e133ac Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期四, 04 五月 2023 14:15:16 +0800 Subject: [PATCH] 1 --- ExportMap/db/PostgreHelper.cs | 26 ++++++++++++++++++++++++++ 1 files changed, 26 insertions(+), 0 deletions(-) diff --git a/ExportMap/db/PostgreHelper.cs b/ExportMap/db/PostgreHelper.cs index 6a19629..8659d6d 100644 --- a/ExportMap/db/PostgreHelper.cs +++ b/ExportMap/db/PostgreHelper.cs @@ -134,6 +134,32 @@ } } + public int GetIntScalar(string sql, params DbParameter[] args) + { + using (NpgsqlConnection con = new NpgsqlConnection(ConStr)) + { + if (con.State != ConnectionState.Open) + { + con.Open(); + } + + using (NpgsqlCommand cmd = new NpgsqlCommand(sql, con)) + { + if (args != null) + { + foreach (DbParameter arg in args) + { + cmd.Parameters.Add(arg); + } + } + + object obj = cmd.ExecuteScalar(); + + return null == obj ? 0 : Convert.ToInt32(obj); + } + } + } + /// <summary> /// 鎵цSQL锛岃繑鍥炲奖鍝嶈鏁� /// </summary> -- Gitblit v1.9.3