Search This Blog

Tuesday, March 25, 2014

Filter with LINQ DataTable C#

C# > System.Data   > DataTable > Filter with LINQ

Example:


DataTable dt = new DataTable("table");
dt.Columns.Add("id", Type.GetType("System.Int32"));
dt.Columns.Add("name", Type.GetType("System.String"));

DataRow dr = dt.NewRow();
dr["id"] = 1;
dr["name"] = "john";
dt.Rows.Add(dr);

dr = dt.NewRow();
dr["id"] = 2;
dr["name"] = "dan";
dt.Rows.Add(dr);

DataTable tbl = (from DataRow dr1 in dt.Rows
                     where dr1["id"].ToString() == "1"
                     select dr).CopyToDataTable();





Friday, March 21, 2014

DateValue Visual Basic Example

VB.NET Functions > DateValue 

Returns a date value containing the date information represented by a string.

Example

Dim dt As Date
dt = DateValue("March 21, 2014")

MessageBox.Show(dt)






Oracle Sequence Example

OracleSequence

Sequences are database objects from which multiple users can generate unique integers. The sequence generator generates sequential numbers, which can help to generate unique primary keys automatically, and to coordinate keys across multiple rows or tables.


Example:

CREATE SEQUENCE order_sequence
      INCREMENT BY 1
      START WITH 1
      NOMAXVALUE
      NOCYCLE
      CACHE 10;

INSERT INTO orders (order_no)
VALUES (order_sequence.NEXTVAL);





Wednesday, March 19, 2014

Var C# Example

C#Types > Var

Var is implicitly typed.

An implicitly typed local variable is strongly typed, but 

the compiler determines the type. 


Example


// var is required because the select clause specifies an anonymous type 

var query = from prod in products
            where prod.Category == "shoes"
            select new { prod.Name, prod.Price };

// var is required because item is an anonymous type
foreach (var item in query)
{
               

}




C# Void Type Example

C# > Types > Void

Void specifies that the method doesn't return a value.

Example


private void Log(string msg)
{
   // log method

}






SQL Server Drop

SQL Server > DDL > Drop

DROP statements removes existing entities.




DateDiff Visual Basic Example

VB.NET Functions > DateDiff

Returns a value specifying the number of time intervals 
between two dates.

Example:


Dim dt1 As Date = #3/1/2014#
Dim dt2 As Date = #4/1/2014#

MessageBox.Show("Day diff: " & DateDiff(DateInterval.Day, dt1, dt2) & " Week diff: " & DateDiff(DateInterval.Weekday, dt1, dt2))