Search This Blog

Thursday, February 7, 2013

SQL query result insert in temp table

SQL Server > Create dynamic temp table

Select into create dynamical temporary table

Example

SELECT
   *
into
   #t
FROM
  table




Call REST (C#)

C# > WebRequestMethods.Http.Get

WebRequestMethods.Http.Get: Represents an HTTP GET protocol method.

The GET method retrieves the information or entity that is identified by the URI of the request.

Example:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication3
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            string Uri = "Your Uri";
            String text;
            HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(Uri);
            myReq.Method = WebRequestMethods.Http.Get;
            myReq.Accept = "application/json";

            HttpWebResponse response = (HttpWebResponse)myReq.GetResponse();
            using (var sr = new StreamReader(response.GetResponseStream()))
            {
                text = sr.ReadToEnd();
            }
        }
    }
}







Location and Size (C#)

C# > Controls > Location and Size

Location

Gets or sets the coordinates of the upper-left corner of the control relative to the upper-left corner of its container.

Size

Gets or sets the height and width of the control.

Example

label1.Location = new Point(4, 302);
label1.Size = new Size(85, 13);






Add dynamic event to controls (C#)

C# > ComponentModelCancelEventHandler 

Delegates the method that handles a cancel event.

Example

Add dynamic event to TextBox


txtReportHeader.Validating += new CancelEventHandler(MyValidating);
private void MyValidating(object sender, CancelEventArgs e)
{
     // some validation
}







Set font bold label (C#)

C# > Drawing > Font > Bold

Bold indicates when Font is bold.

Example:
label1.Font = new System.Drawing.Font(label1.Font, FontStyle.Bold);




Tuesday, January 29, 2013

?: Operator (Ternary) (C#)

C# > OperatorsTernary (?:)

Ternary (conditional) operator (?:) returns one of two values depending on the value of a Boolean expression.

The syntax for the ternary operator is

condition ? first_expression : second_expression;

Example:




namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private string OddOrEven(int x)
        {
            return (x % 2 == 0) ? "Number is even" : "Number is odd";
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            string s;
            s = OddOrEven(10); // Number is even
            s = OddOrEven(11); // Number is odd
        }
    }
}










Verbatim String Literals (C#)

C# > Verbatim String Literals 

In a verbatim string literal, the characters between the delimiters are interpreted verbatim, the only exception being a quote-escape-sequence.

Suppose you want to set a string as following:

string path = "C:\\Programs\\MyProgram\\My.exe";


You can use the verbatim string literal character (@) to build the string exactly as it appears within the double quotation marks.
string path = @"C:\Programs\MyProgram\My.exe";