12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- using Npgsql;
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using WWPipeLine.Commons;
- namespace WWPipeLine.MapBasic
- {
- public class NpgsqlHelper
- {
- public NpgsqlHelper() { }
- //HOST=39.99.237.110;PORT=5432;DATABASE=weiweiGIS110;USER ID=postgres;PASSWORD=wwkj@2136807;
- //ComsStatic.getMd5Hash("", "ww");
- private static string ConStr = IniHelper.Read(IniHelper.KEY_ConfigsNpgsql_PATH);
- public int ExecuteNonQuery(string sql)
- {
- int result = -1;
- using (NpgsqlConnection connection = new NpgsqlConnection(ConStr))
- {
- using (NpgsqlCommand command = new NpgsqlCommand(sql, connection))
- {
- try
- {
- connection.Open();
- result = command.ExecuteNonQuery();
- }
- catch (NpgsqlException exception)
- {
- LogHelper.Error(string.Format("执行SQL[{0}]出错,详细信息为:{1}", sql, exception.Message));
- }
- finally
- {
- connection.Close();
- }
- }
- }
- return result;
- }
- public object ExecuteScalar(string sql)
- {
- object obj = null;
- using (NpgsqlConnection connection = new NpgsqlConnection(ConStr))
- {
- using (NpgsqlCommand command = new NpgsqlCommand(sql, connection))
- {
- try
- {
- connection.Open();
- obj = command.ExecuteScalar();
- }
- catch (NpgsqlException exception)
- {
- LogHelper.Error(string.Format("执行SQL[{0}]出错,详细信息为:{1}", sql, exception.Message));
- }
- finally
- {
- connection.Close();
- }
- }
- }
- return obj;
- }
- public DataSet ExecuteQuery(string sql)
- {
- DataSet result = new DataSet();
- using (NpgsqlConnection connection = new NpgsqlConnection(ConStr))
- {
- using (NpgsqlDataAdapter dataAdapter = new NpgsqlDataAdapter(sql, connection))
- {
- try
- {
- connection.Open();
- dataAdapter.Fill(result);
- }
- catch (NpgsqlException exception)
- {
- LogHelper.Error(string.Format("执行SQL【{0}】出错,详细信息为:{1}", sql, exception.Message));
- }
- finally
- {
- connection.Close();
- }
- }
- }
- return result;
- }
- }
- }
|