Пример #1
0
        public static DataTable callsql(string sql)
        {
            DataTable dt = new DataTable();

            try
            {
                NpgsqlConnection cn;
                cn = ConnectionServer.CreateConnection();
                //NpgsqlDataAdapter da;
                //da = new NpgsqlDataAdapter(sql, cn);
                NpgsqlCommand    cmd    = new NpgsqlCommand(sql, cn);
                NpgsqlDataReader reader = cmd.ExecuteReader();
                //da.Fill(dt);
                dt.Load(reader);
                cn.Close();
                return(dt);
            }
            catch (Exception ex)
            {
                MessageBox.Show("SQL executeschalar moethod failed." + System.Environment.NewLine + ex.Message
                                , "Database Responce", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                ConnectionServer.CreateConnection().Close();
                return(dt);
            }
        }
 public string callsql(string sql)
 {
     try
     {
         NpgsqlConnection cn;
         cn = ConnectionServer.CreateConnection();
         NpgsqlCommand command = new NpgsqlCommand(sql, cn);
         esql = Convert.ToString(command.ExecuteScalar());
         cn.Close();
         return(esql);
     }
     catch (Exception ex)
     {
         MessageBox.Show("SQL executeschalar moethod failed." + System.Environment.NewLine + ex.Message
                         , "Database Responce", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         ConnectionServer.CreateConnection().Close();
         return(esql);
     }
 }