Search This Blog

Friday, August 14, 2015

SOUNDEX SQL Server Example

SQL Server > Built-in Functions > SOUNDEX

SOUNDEX converts an alphanumeric string to a four-character code that is based on how the string sounds when spoken. 

Example


SELECT SOUNDEX ('Jan'), SOUNDEX ('Jane');

Result:
(No column name) (No column name)
J500                 J500






TRY_CAST SQL Server Example

SQL Server > Built-in Functions > TRY_CAST

Try to cast a value to the specified data type. 
If the cast not succeeds returns null.

Example


SELECT
    CASE WHEN TRY_CAST('1' AS float) IS NULL
    THEN 'Cast failed'
    ELSE 'Cast succeeded'
END AS Result;

Result
Cast succeeded

SELECT
    CASE WHEN TRY_CAST('xx' AS float) IS NULL
    THEN 'Cast failed'
    ELSE 'Cast succeeded'

END AS Result;

Result
Cast failed





Monday, August 10, 2015

Pow C# Example

C#  > System > Math class > Pow

Pow  number raise a  number to the specified power.

Example:

double pow = Math.Pow(2, 8); // 256




Tuesday, August 4, 2015

Scroll to selected index DataGridView

C# > DataGridViewFirstDisplayedScrollingRowIndex 

Setting this property raises scroll event to match selected index.


Example


dataGridView1.FirstDisplayedScrollingRowIndex = dataGridView1.Rows.Count - 1;




Friday, July 31, 2015

Read fast text file line by line C#

C# > Files > File Class > OpenText

Open text file for reading line by line.

Example

Read fast text file line by line C#

using (StreamReader sr = File.OpenText(@"c:\filename.txt"))
{
   while (!sr.EndOfStream)
   {
     sr.ReadLine();
    }
}







Monday, July 27, 2015

INSERT SQL Server Example

SQL Server > DML > INSERT

INSERT adds one or more rows to a table or a view.


  • When insert data into a view, the view must reference exactly one base table in the FROM clause of the view. 
  • When insert into a multi-table view you must use a column list that references only columns from one base table. 


Example


INSERT INTO Sales (ProductName, Price, [Date])
VALUES ('Product1', 200, GETDATE());




Friday, July 24, 2015

How to bind to a parent DataContext WPF

WPF > RelativeSource



IsEnabled="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Path=DataContext.IsAPGCSourceFitted}"