Search This Blog

Wednesday, May 28, 2014

Lower SQL Server Example

SQL Server > Built-in Functions > LOWER

Converts uppercase character data to lowercase.

Example

SELECT lower('SQL SERVER')

Result:

sql server




Friday, May 23, 2014

Dictionary C# Example

C# > Generics > Dictionary 

Dictionary is a collection of keys and values.
Retrieving a value by using its key is very fast because the Dictionary class is implemented as a hash table.

Example


    Dictionary<string, string> accesCode = new Dictionary<string, string>();

            accesCode.Add("AAA", "PERSON 1");
            accesCode.Add("BBB", "PERSON 2");
            accesCode.Add("CCC", "PERSON 3");

            string code = "";
            accesCode.TryGetValue("xxx", out code); // code = null
            accesCode.TryGetValue("CCC", out code); // code = PERSON 3

            if (!accesCode.ContainsKey("DDD"))
                accesCode.Add("DDD", "PERSON 4");


            foreach (KeyValuePair<string, string> kvp in accesCode)
            {
                MessageBox.Show(kvp.Key + kvp.Value);
            }





Thursday, May 22, 2014

Join two tables Linq example C#

C# > LINQ > Join

Join is association of objects that share a common attribute.


Example:


DataTable dtOrder = new DataTable("order");
dtOrder.Columns.Add("id", Type.GetType("System.Int32"));
dtOrder.Columns.Add("customer", Type.GetType("System.String"));

DataRow dr = dtOrder.NewRow();
dr["id"] = 1;
dr["customer"] = "X Company";
dtOrder.Rows.Add(dr);

dr = dtOrder.NewRow();
dr["id"] = 2;
dr["customer"] = "Y Company";
dtOrder.Rows.Add(dr);

DataTable dtProduct = new DataTable("product");
dtProduct.Columns.Add("order_id", Type.GetType("System.Int32"));
dtProduct.Columns.Add("product", Type.GetType("System.String"));

dr = dtProduct.NewRow();
dr["order_id"] = 1;
dr["product"] = "Product 1";
dtProduct.Rows.Add(dr);

dr = dtProduct.NewRow();
dr["order_id"] = 1;
dr["product"] = "Product 2";
dtProduct.Rows.Add(dr);

var orderProducts = from order in dtOrder.AsEnumerable()
                    join product in dtProduct.AsEnumerable() on order.Field<int>("id")                               equals product.Field<int>("order_id")
                     select new
                                {
                                    OrderId = order.Field<int>("id"),
                                    Product = product.Field<string>("product")

                                };





Tuesday, May 20, 2014

StringBuilder C# Example

C# > Text > StringBuilder 

StringBuilder is used when

  • you want to create or modify a string without creating a new object
  • increase performance when concatenating many strings together in a loop.


Example:


StringBuilder str = new StringBuilder("Product 1");

str.AppendLine(); // new line
str.Append("Product 2");
str.AppendLine();
str.AppendFormat("Total {0:C} ", 40);

textBox1.Text = str.ToString();




XElement C# Example

C# > LINQ > LINQ TO XML > XElement

XElement is an XML element.
With XElement you can create, change, delete elements.

Example


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml.Linq;






namespace WindowsFormsApplication9
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            XElement coTree = new XElement("Company",
                new XElement("Dept", 1),
                new XElement("Dept", 2),
                new XElement("Dept", 3));

            XElement co1Tree = new XElement("Company1",
                new XElement("CEO", 1),
                new XElement("Manager", 2),
                from el in coTree.Elements()
                    where (int)el < 3 
                        select el);
            textBox1.Text = co1Tree.ToString();
 
        }
    }
}





Monday, May 19, 2014

LINQ Enumerable Except Example

C# > LINQ > Enumerable > Except

Produces the set difference of two sequences


Example

            double[] num1 = { 1.0, 1.1 , 1.2  };
            double[] num2 = { 1.1 };

            var onlyInNum1 = num1.Except(num2);

            foreach (double number in onlyInNum1)





Determining NLS_DATE_FORMAT Oracle

OracleNLS_DATE_FORMAT

NLS_DATE_FORMAT specifies the default date format to use with the TO_CHAR and TO_DATE functions

Example:
Get NLS_DATE_FORMAT 

SELECT value
FROM   nls_session_parameters
WHERE  parameter = 'NLS_DATE_FORMAT'

Result: