Search This Blog

Wednesday, November 27, 2013

System Namespace VB.NET

VB.NET > System namespace

System namespace in VB.NET contains fundamental classes and base classes.

String






Tuesday, November 26, 2013

Create CDATA section XML C#

C# > XML > XmlDocument > CreateCDataSection

CreateCDataSection creates an XmlCDataSection.
CDATA is a section used to quote or escape blocks of text to keep that text from being interpreted as markup language.

Example:

XmlDocument doc = new XmlDocument();
doc.LoadXml("<product ID='1'></ product>");
//Create a CData section
XmlCDataSection CData;
CData = doc.CreateCDataSection("Size is 10/55");

//Add the new node to the document
XmlElement root = doc.DocumentElement;
root.AppendChild(CData);
doc.Save("C:\\Products.xml");

Result:
  <![CDATA[Size is 10/55]]>
</product>





Monday, November 25, 2013

Short type C# Example

C# > Types > short

The short keyword is an integral type.
Range: -32768 to 32767

Size: Signed 16-bit integer

Example:

short k = 32767; // ok
k = 32768; // Error Constant value '32768' cannot be converted to a 'short'




Struct in C# Example

C# > Types > Struct

A struct type is a value type and is typically used for representing lightweight objects (color, zip, point).
  • cannot inherit from another struct or class
  • can be instantiated without using a new operator.
  • can implement an interface
  • can contain fields, constructors, methods, operators and events, but
  • if many members are required  you should make your type a class instead
Note:  Struct might be more efficient than a class in some scenarios. Using array of thousand of objects will be allocate more memory for referencing each object, so in this case, a struct would is more efficient and less expensive.






Example

        public struct strColor
        {
            public int r, g, b;
            public strColor(int p1, int p2, int p3)
            {
                r = p1;
                g = p2;
                b = p3;
            }
        }
       // Initialize using default and parameterized constructor
       strColor color1 = new strColor();
       strColor color2 = new strColor(10, 20, 30);
      // Declare object. It creates object without using the new  operator
       strColor color;
      //Initialize
       color.r = 10;
       color.g = 20;
       color.b = 30;





SQL Server sp_server_info example

SQL Server > System Stored Procedures   > sp_server_info

Sp_server_info returns a list of attribute names and values for SQL Server.

Example:

exec sp_server_info
Result:
attribute_id  attribute_name       attribute_value

1      DBMS_NAME     Microsoft SQL Server
2      DBMS_VER      Microsoft SQL Server 2012 - 11.0.2100.60 - 11.0.2100.60
10     OWNER_TERM    owner
11     TABLE_TERM    table
12     MAX_OWNER_NAME_LENGTH      128
13     TABLE_LENGTH  128
14     MAX_QUAL_LENGTH      128
15     COLUMN_LENGTH 128
16     IDENTIFIER_CASE      MIXED
17     TX_ISOLATION  2
18     COLLATION_SEQ charset=iso_1 sort_order=nocase_iso charset_num=1 sort_order_num=52
19     SAVEPOINT_SUPPORT    Y
20     MULTI_RESULT_SETS    Y
22     ACCESSIBLE_TABLES    Y
100    USERID_LENGTH 128
101    QUALIFIER_TERM       database
102    NAMED_TRANSACTIONS   Y
103    SPROC_AS_LANGUAGE    Y
104    ACCESSIBLE_SPROC     Y
105    MAX_INDEX_COLS       16
106    RENAME_TABLE  Y
107    RENAME_COLUMN Y
108    DROP_COLUMN   Y
109    INCREASE_COLUMN_LENGTH     Y
110    DDL_IN_TRANSACTION   Y
111    DESCENDING_INDEXES   Y
112    SP_RENAME     Y
113    REMOTE_SPROC  Y
500    SYS_SPROC_VERSION    11.00.2100




sp_tables SQL Server Example

SQL Server > System Stored Procedures   > sp_tables

Returns a list of tables and views that can be queried in the current environment.

Example:

EXEC sp_tables;


 





LINQ Query Expressions C# example

C# > LINQ Query Expressions

Language-Integrated Query (LINQ) is the name for a set of technologies of .NET Framework. This component adds data query  capabilities directly into the C# language.
LINQ expressions are like SQL statements  and can be used to extract and process data from arrays, classes, XML and databases.

Data Source - Query Expression - Execute

Methods
Examples

Example 1.  Fundamental query concepts

            // data source
            int[] int_array = new int[] { 5, 4, 2, 8, 10 };

            // query expression
            IEnumerable<int> intQuery =
                from int_v in int_array
                where int_v >= 5
                select int_v;

            // Execute the query
            foreach (int i in intQuery)
            {
                MessageBox.Show(i.ToString());
            } 
    
Example 2. Order by query

            IEnumerable<int> intQuery =

                from int_v in int_array
                where int_v >= 5
                orderby int_v ascending
                select int_v;

Example 3.
Implement RANK function


Example 4. IsNumeric

Example 5. Order By Key Dictionary