Search This Blog

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}"

Monday, July 20, 2015

Day VB.Net Example

VB.NET > Functions > Day

Day returns the day of the month as an integer between 1 and 31.

Example


Dim today As Integer = Microsoft.VisualBasic.DateAndTime.Day(Now)






Wednesday, June 24, 2015

C# Regex to match the words with dot

C#Text > Regular Expressions > Split with dot


 string[] substrings = Regex.Split("test.regex.dot", @"\.");




Thursday, June 18, 2015

Remove border Telerik RadGridView

Telerik > RadGridView > Remove border

radGridView1.GridViewElement.DrawBorder = false;
radGridView1.GridViewElement.GroupPanelElement.DrawBorder = false;






Monday, June 15, 2015

KeyNotFoundException Collection C# Example

Collections > Generic > KeyNotFoundException 

This is thrown when try to retrieve an element from a collection using a key that does not exist in that collection.

Example

   Dictionary<string, string> dict = new Dictionary<string, string>();
   dict.Add("key1","value1");
   try
   {
       string val = dict["key2"];
   }
   catch (KeyNotFoundException)
   {
       throw new KeyNotFoundException("KeyNotFoundException!");

   }