Friday, January 17, 2014

Visual Studio Shortcuts



General Short Cuts:

Ctrl-X or Shift-Delete or Ctrl-L: Cuts entire line or Cuts the currently selected item to the clipboard
Ctrl-Del: Delete next "word"
Ctrl-C or Ctrl-Insert: Copies the currently selected item to the clipboard
Ctrl-V or Shift-Insert: Pastes the item from the clipboard at the cursor location
Ctrl-Z or Alt-Backspace: Undo the previous editing action
Ctrl-Space: To see intelligence dialog
Ctrl-Y or Ctrl-Shift-Z: Redo the previous undo action
Ctrl-S: Saves the current selected file
Ctrl-Shift-S: Saves all files and projects
Ctrl-P: Displays the Print dialog
F7: Switches from the design view to the code view in the editor
Shift-F7: Switches from the code view to the design view in the editor
Shift-F8 or F8: Navigate to compile time errors
Alt-Shift-A: Add Existing Item(file) to selected project
Ctrl-Shift-A: Add New Item(file) to selected project
Shift-F9: Display the selected item quick output means contains value while debugging
F12: Moves the cursor to the selected method, variable, class definition.
Shift-F12: Finds the reference to the selected method, variable, class or the item under the cursor
Ctrl-}: Match curly braces, brackets or compiler directives
Ctrl-Shift-}: Select text between matched braces, brackets or compiler directives

Text manipulation Shortcut Description:

Tab: Indents the currently selected line or lines by one tab stop. If there is no selection, this inserts a tab stop
Tab-Tab: Complete the syntax of an item. Example- Write for and now press Tab-Tab, then for loop syntax will be automatically completed. Similarly it works for property, index, class syntax.
Shift-Tab: Moves current line or selected lines one tab stop to the left
Backspace or Shift-Backspace: Deletes one character to the left of the cursor
Ctrl-K, Ctrl-C: Marks the current line or selected lines of code as a comment, using the correct comment syntax for the programming language
Ctrl-K, Ctrl-U: Removes the comment syntax from the current line or currently selected lines of code
Ctrl-K, Ctrl-D: Do proper alignment of all the code of design view and code view
Ctrl-T or Shift-Enter: Swaps the characters on either side of the cursor. (For example, AC|BD becomes AB|CD.) Available only in text editors
Ctrl-U: Changes the selected text to lowercase characters
Ctrl-Shift-U: Changes the selected text to uppercase characters
Ctrl-Shift-Right Arrow: Select the entire word with space from start to end
Ctrl-Right Arrow: Move the cursor in forward direction word by word
Shift-End: Select the entire line from start to end
Shift-Home: Select the entire line from end to start
Shift-Alt-Arrows or Alt-Mouse: Column wise text selection for text manipulation
Ctrl-Delete: Deletes the word to the right of the cursor
Ctrl-Backspace: Deletes the word to the left of the cursor
Ctrl-G: Jump to line number or go to line

Project related Shortcut Description:

Ctrl-Shift-B: Builds the solution
Ctrl-N: Displays the New File dialog. Note: files created this way are not associated with a project. Use Ctrl-Shift-A to add a new file in a project
Ctrl-Shift-N: Displays the New Project dialog
Ctrl-O: Displays the Open File dialog
Ctrl-Shift-O: Displays the Open Project dialog
Ctrl-M-O: Collapse all the methods, classes, regions in the current code behind or class file
Ctrl-M-P or Ctrl-M-L: Expands all the methods, classes, regions in the current code behind or class file
Ctrl-F: Displays the Find dialog
Ctrl-H: Displays the Replace dialog
Ctrl-Shift-F: Find the reference of selected item into entire solution.
Ctrl-Tab: Move from one opened file to another opened file in visual studio.
F9: Sets or removes a breakpoint at the current line
Ctrl-F9: Enables or disables the breakpoint on the current line of code. The line must already have a breakpoint for this to work
F5: Runs the code with invoking the debugger.
Ctrl-F5: Runs the code without invoking the debugger.
F4 or Alt-Enter: Displays the Properties window, which lists the design-time properties and events for the currently selected item
Ctrl-Alt-S: Displays the Server Explorer window, which allows you to view and manipulate database servers, event logs, message queues, web services, and many other operating system services
Ctrl-Alt-L: Displays the Solution Explorer, which lists the projects and files in the current solution
Ctrl-Alt-X: Displays the Toolbox, which contains controls and other items that can be dragged into editor and designer windows
Ctrl-Alt-I: Displays the Immediate window, where you can find the controls or variables values or can do data manipulation during debugging

Wednesday, January 15, 2014

Getting First and Last Date of the Current Week in sql.

This Post will Explain how we can get the First Date and Last Date of the Current Week or for a given random date if Supplied in sql server.
Here in the Example Below getdate() function is used to get the  todays date. You can make it input field in stored procedure to generalize this procedure for any date and not just current date.

DateADD(interval,increment int,date) Function adds the increment int no of days to the date times the interval, here interval is d which days. Hence 1-datepart(dw,getdate()) no of days are added to the current date.

DatePart(interval,date) gets the date part in interval provided. In our example interval is week day dw hence, datepart gets the what date (1-7) in week is for the given date.


in our example we add the number of day of the week for the date subtracted from 1 for first day which will result in subtracting 2 (1-3) days if today is 3rd day of the week (Tuesday) resulting in sunday's date.
for last day of the week 7-3 will be 4 a positive no which will be added to todays date resulting in saturdays date.

Example:

DECLARE @Startdt Date
DECLARE @Enddt Date
DECLARE @temptbl Table(StartDate Date, EndDate Date)
SET @Startdt= dateadd(d,1-datepart(dw,getdate()),getdate())
SET @Enddt =dateadd(d,7-datepart(dw,getdate()),getdate())

INSERT INTO @temptbl VALUES(@Startdt,@Enddt)
SELECT * FROM @temptbl

Tuesday, January 14, 2014

Inserting Data in SQL from XML file using Stored Proceduer.

This Post will explain how we can upload data in sql server after reading an XML file.
uses:
1. Importing of data to sql server for application like Excel can be done with help of XML conversion of Excel Data and then Inserting it using this process to upload in the sql database.

2.Other XML Data Generated by application can be inserted in to the data base at once hence reducing network traffic for slow networks.

example:
-- below is the syntax to Create a Stored Procedure for Insertion of data in to the table with XML data
Create Procedure prUpload_XML
@P_XML XML=null
AS
BEGIN
insert into table_Name
(
Column1,
Column2,
Column3
)
SELECT
T.Item.value('(@Column1)[1]','nvarchar(50)'),
T.Item.value('(@Column2)[1]','nvarchar(10)'),
T.Item.value('(@Column3)[1]','nvarchar(50)')
 FROM    @P_XML.nodes('/items/item') AS T ( Item )

--Here items is the name of XML file uploaded and item is the tag for each row in the XML.