drupal stats

C#

Get Connection String from app.config, web.config

Get connection string by connection’s name

string conn = ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString;

 

or

string conn = ConfigurationManager.ConnectionStrings[1].ToString();



Copying Rows from One Table to Another – C#

Use Clone method to copy the table structure (Schema)

DataTable dtProductCopy = new DataTable();

dtProductCopy = dtProduct.Clone();

 

Use the ImportRow method to copy from Product table to its clone

for (int i = 0; i < dtProduct.Rows.Count; ++i)

{

    dtProductCopy.ImportRow(dtProduct.Rows[i]);

}

Get Windows Folder using C#

Environment.GetEnvironmentVariable("SystemRoot");

 

or

Environment.GetEnvironmentVariable("windir");

Get current username in Windows using C#

System.Security.Principal.WindowsIdentity.GetCurrent().Name;

Get the Computer Name using C#

System.Windows.Forms.SystemInformation.ComputerName.ToString();

or

System.Environment.MachineName;

Page 1 of 41234