Tips and Tricks
Come visualizzare tutti i nomi dei database Sql Server con Visual C#
0Nell’esmpio riportato di seguito, vi riporto una semplice procedura per recuperare tutti i nomi dei database sql server utilizzando Visual C# :
using System.Data;
using System.Data.SqlClient;
...
// Sostituire con la propria stringa di connessione
String conxString = "Data Source=MYSERVER; Integrated Security=True;";
using (SqlConnection sqlConx = new SqlConnection (conxString))
{
sqlConx.Open();
DataTable tblDatabases = sqlConx.GetSchema ("Databases");
sqlConx.Close();
foreach (DataRow row in tblDatabases.Rows)
{
Console.WriteLine ("Database: " + row["database_name"]);
}
}
Come scrivere una chiave nel registro di Windows con Visual C#
0
using Microsoft.Win32;
...
RegistryKey masterKey = Registry.LocalMachine.CreateSubKey("SOFTWARE\\Test\\Preferences");
if (masterKey == null)
{
Console.WriteLine ("Null Masterkey!");
}
else
{
try
{
masterKey.SetValue ("MyKey", "MyValue");
}
catch (Exception ex)
{
Console.WriteLine (ex.Message);
}
finally
{
masterKey.Close();
}
}
Come leggere una chiave dal registro di Windows con Visual C#
0Nell’ esempio che segue viene mostrato come leggere una chiave del registro di Windows utilizzando Visual C# ed il .Net Framework :
using Microsoft.Win32;
...
RegistryKey masterKey = Registry.LocalMachine.CreateSubKey("SOFTWARE\\Test\\Preferences");
if (masterKey == null)
{
Console.WriteLine ("Null Masterkey!");
}
else
{
Console.WriteLine ("MyKey = {0}", masterKey.GetValue ("MyKey"));
}
masterKey.Close();
[WordPress] : Come contare i commenti dei Post
0
<? $pop = $wpdb->get_results(SELECT ID,post_title,comment_count FROM {$wpdb->prefix} posts WHERE post_type ='post' ODER BY comment_count DESC LIMIT 10 );
foreach($pop as $post) : ?>
<li> <?php echo $post->post_title; ?> </li>
<?php endforeach; ?>
[C#] : Come scansionare un Array con LINQ
0
using System;
using System.Collections;
using System.Collections.Generic;
namespace ForEachExaple
{
public static class Utility
{
public static void ForEach(this IEnumerable coll, Action function)
{
IEnumerator en = coll.GetEnumerator();
while (en.MoveNext())
function(en.Current);
}
}
class Program
{
static void Main(string[] args)
{
var array = new int[] { 1, 2, 3 };
//Output : 123
array.ForEach(val => Console.Write(val));
}
}
}
[C#] : Come inviare una mail con gmail
1![fuori tutto youbuy pcfuori [C#] : Come inviare una mail con gmail](http://www.luigimelisi.com/wp-content/uploads/2010/06/pcfuori.jpg)
Ecco un metodo sempice e veoloce per inviare una mail da Gmail con C# :
1 2 3 4 5 6 7 8 9 10 11 12 13 | string host = "smtp.gmail.com"; int port; //port = 587; // with TLS //port = 465; // with SSL port = 25; // normal ‐ works for my gmail account with enableSSL string fromEmail = "myemail@mydomain.com"; var fromAddress = new MailAddress(fromEmail); var toAddress = new MailAddress("myemail@aDifferentDomain.com"); MailMessage message = new MailMessage(fromAddress, toAddress) { Subject = "subject", Body = "body", }; |
[C#] : Come passare da Excel a Datatable
01 2 3 4 5 6 7 8 9 10 | string connectionString = string.Format("Provider = Microsoft.Jet.OLEDB.4.0; data source = {0};Extended Properties=Excel 8.0;",file); OleDbDataAdapter = new OleDbDataAdapter("SELECT * FROM [TABLES1$]",connectionString); DataSet ds = new DataSet(); adapter.Fill(ds,"Name"); DataTable dt = ds.Tables["Name"]; |
[.NET Framework 4.0] : Session State Compression
0ASP.NET consente di scegliere tra tre possibili opzioni per memorizzare i dati di sessione.
La prima possibilità, quella di default, consiste semplicemente nel mantenere i dati di sessione in memoria nello stesso processo dell’applicazione ASP.NET.
La seconda consente di tenere i dati di sessione sempre in memoria ma nella memoria di una macchina server dedicata (quindi solitamente una macchina diversa da quella che ospita l’applicazione).

![Last Minute last60 225x300 [C#] : Come scansionare un Array con LINQ](http://www.luigimelisi.com/wp-content/uploads/2010/06/last60-225x300.jpg)