/* Check for active FTP connection */
var FTPErrorMessage = CheckIfFTPConnectionIsActive();
if (string.IsNullOrEmpty(FTPErrorMessage) == false)
{
throw new Exception(FTPErrorMessage);
}
/// <summary>
/// CheckIfFTPConnectionIsActive
/// </summary>
/// <param name="lessorName"></param>
private static string CheckIfFTPConnectionIsActive()
{
string errorMessage = string.Empty;
var FtpPath = AppSettingReader.GetStringValue("FtpPath");
var FtpUserName = AppSettingReader.GetStringValue("FtpUserNameUp");
var FtpPassword = AppSettingReader.GetStringValue("FtpPasswordUp");
FtpWebRequest ftp = (FtpWebRequest)FtpWebRequest.Create(FtpPath);
ftp.Credentials = new NetworkCredential(FtpUserName, FtpPassword);
ftp.KeepAlive = false;
ftp.Method = WebRequestMethods.Ftp.ListDirectory;
ftp.UsePassive = false;
try
{
FtpWebResponse response = (FtpWebResponse)ftp.GetResponse();
}
catch (WebException ex)
{
errorMessage = ex.Status.ToString();
}
catch (Exception e)
{
errorMessage = e.Message.ToString();
}
return errorMessage;
}
Sunday, 24 March 2013
Friday, 15 March 2013
SQL Server Isolation Levels By Example
SQL Server 2008 supports the following isolation levels
- Read Uncommitted
- Read Committed (The default)
- Repeatable Read
- Serializable
- Snapshot
More Details:
Thursday, 14 March 2013
Styling Excel cells with mso-number-format
///Styling Excel cells with mso-number-format
| mso-number-format:"0" | NO Decimals |
| mso-number-format:"0\.000" | 3 Decimals |
| mso-number-format:"\#\,\#\#0\.000" | Comma with 3 dec |
| mso-number-format:"mm\/dd\/yy" | Date7 |
| mso-number-format:"mmmm\ d\,\ yyyy" | Date9 |
| mso-number-format:"m\/d\/yy\ h\:mm\ AM\/PM" | D -T AMPM |
| mso-number-format:"Short Date" | 01/03/1998 |
| mso-number-format:"Medium Date" | 01-mar-98 |
| mso-number-format:"d\-mmm\-yyyy" | 01-mar-1998 |
| mso-number-format:"Short Time" | 5:16 |
| mso-number-format:"Medium Time" | 5:16 am |
| mso-number-format:"Long Time" | 5:16:21:00 |
| mso-number-format:"Percent" | Percent - two decimals |
| mso-number-format:"0%" | Percent - no decimals |
| mso-number-format:"0\.E+00" | Scientific Notation |
| mso-number-format:"\@" | Text |
| mso-number-format:"\#\ ???\/???" | Fractions - up to 3 digits (312/943) |
| mso-number-format:"\0022£\0022\#\,\#\#0\.00" | £12.76 |
| mso-number-format:"\#\,\#\#0\.00_ \;\[Red\]\-\#\,\#\#0\.00\ " | 2 decimals, negative numbers in red and signed (1.56 -1.56) |
Wednesday, 13 March 2013
Comma separated values using linq from dataset in C#
//Comma separated values using linq from dataset in C#
DataSet ds = new DataSet();System.Data.DataTable dtResults = new System.Data.DataTable();
System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection("server=testserver;uid=testuser;pwd=pwd;database=testDB");
con.Open();
System.Data.SqlClient.SqlCommand cmd = new SqlCommand("SPName", con);
cmd.CommandType = CommandType.StoredProcedure;
SqlDataAdapter DA = new SqlDataAdapter(cmd);
DA.Fill(ds);
if (ds.Tables != null && ds.Tables[0].Rows.Count > 0)
{
string ourstring = String.Join(",", ds.Tables[0].AsEnumerable().Select(x => x.Field<int> ("ColumnName").ToString()).ToArray());
}
Sample Linq program in C#
using System;
using System.Data;
class Program {
public void DisplayProducts(DataTable table) {
var productNames = from products in table.AsEnumerable() where products.Field<int>("ID") > 1 select products.Field<string>("ProductName");
Console.WriteLine("Product Names: ");
foreach (string productName in productNames)
{
Console.WriteLine(productName);
}
//DataRow[] test = table.Select("ID>" + 1);
//foreach (DataRow productName in test)
//{
// Console.WriteLine(productName["ProductName"]);
//}
}
static void Main(string[] args) {
DataTable table = new DataTable();
table.Columns.Add("ID",typeof(Int32));
table.Columns.Add("ProductName");
table.Rows.Add(1, "Chai");
table.Rows.Add(2, "Queso Cabrales");
table.Rows.Add(3, "Tofu");
table.Rows.Add(4, "Arjun");
table.Rows.Add(5, "Kamal");
table.Rows.Add(6, "Vijay");
Program inst = new Program();
inst.DisplayProducts(table);
Console.ReadLine();
}
}
using System.Data;
class Program {
public void DisplayProducts(DataTable table) {
var productNames = from products in table.AsEnumerable() where products.Field<int>("ID") > 1 select products.Field<string>("ProductName");
Console.WriteLine("Product Names: ");
foreach (string productName in productNames)
{
Console.WriteLine(productName);
}
//DataRow[] test = table.Select("ID>" + 1);
//foreach (DataRow productName in test)
//{
// Console.WriteLine(productName["ProductName"]);
//}
}
static void Main(string[] args) {
DataTable table = new DataTable();
table.Columns.Add("ID",typeof(Int32));
table.Columns.Add("ProductName");
table.Rows.Add(1, "Chai");
table.Rows.Add(2, "Queso Cabrales");
table.Rows.Add(3, "Tofu");
table.Rows.Add(4, "Arjun");
table.Rows.Add(5, "Kamal");
table.Rows.Add(6, "Vijay");
Program inst = new Program();
inst.DisplayProducts(table);
Console.ReadLine();
}
}
Subscribe to:
Comments (Atom)