Guest User

Untitled

a guest
Apr 27th, 2018
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.94 KB | None | 0 0
  1. public class PostgreSaver : IDbSaver
  2.     {
  3.         public PostgreSaver()
  4.         {
  5.             npgsqlConnection = new NpgsqlConnection();
  6.             NpgsqlConnectionStringBuilder builder = new NpgsqlConnectionStringBuilder();
  7.             builder.Host = "10.10.1.11";
  8.             builder.Port = 5432;
  9.             builder.UserName = "postgres";
  10.             builder.Password = "123";
  11.             npgsqlConnection.ConnectionString = builder.ConnectionString;
  12.             npgsqlConnection.Open();
  13.         }
  14.  
  15.         public void Save(WebLog webLog)
  16.         {
  17.             NpgsqlCommand command = new NpgsqlCommand();
  18.             command.CommandText = "insert into ping(ping_id, name, url, ip) values(nextval('seq_ping'), @name, @url, @ip)";
  19.             command.Parameters.Add(new NpgsqlParameter("name", webLog.Name));
  20.             command.Parameters.Add(new NpgsqlParameter("url", webLog.Url));
  21.             command.Parameters.Add(new NpgsqlParameter("ip", webLog.Ip));
  22.             command.Connection = npgsqlConnection;
  23.             command.ExecuteNonQuery();
  24.         }
  25.  
  26.         private NpgsqlConnection npgsqlConnection;
  27.     }
Add Comment
Please, Sign In to add comment