Dec 13, 2014

Some useful shortcuts in Visual Studio

Hi the keyboard shortcuts are

F4

F4 is used to show property window.

F5 & Ctrl-F5

F5 is used to start your project in debug mode.
Ctrl-F5 is used to start your project without debug mode.

F6 / Shift-F6 / Ctrl-Shift-B

These are used to build the project or solutions.

F7 & Shift-F7

F7 is used to show code view of your webpage.

Shift-F7 is used to show design view of your webpage.

Ctrl-Shift-A

Ctrl-Shift-A is used to add new item to your project.

Alt-Shift-A

Alt-Shift-A is used to add existing item to your project.


Ctrl-K + Ctrl-C

Ctrl-K + Ctrl-C is used to do comment a selected block of code.

Ctrl-K + Ctrl-U

Ctrl-K + Ctrl-U is used to do uncomment a selected block of code.

Ctrl-M + Ctrl-O

Ctrl-M + Ctrl-O are used to collapse all code to definitions.

Ctrl-M + Ctrl-P

Ctrl-M + Ctrl-P are used to expand all code.


Ctrl-K + Ctrl-S

Ctrl-K + Ctrl-S are used to surround a block of code to a specific block or control.

Alt-Shift-Arrow (Right, Left, Bottom, Top)

Alt-Shift-Arrow (Right, Left, Bottom, Top) are used to copy, paste, write vertically.

Ctrl-(+) + Ctrl-.

Ctrl-(+) + Ctrl-. Is used to display SmartTag under the red line that provides the options for fixing the code problem.

F12

F12 is used to navigate to the definition of an instance, variable, class etc.

Ctrl-Shift-F

Ctrl-Shift-F is used to find all the occurrences of a string with in entire solution and display find result window.

Ctrl-F

Ctrl-F is used to find a string in the current document, project and all open documents one by one.

Ctrl-H

Ctrl-H is used to replace a string by a new string in current document, project and entire solution as you want to replace.

Ctrl-Alt-L


Ctrl-Alt-L is used to show solution explorer.



I hope you will enjoy these shortcut keys.

Please follow for full details, click on below link


Thanks
Rajkumar Palnati

Dec 12, 2014

Some Useful Stuff in Dot Net

1. How to check UserId available in database or not ?

A : First design the page like 


Source Page, 



Code behind, 


 protected void Button1_Click(object sender, EventArgs e)


        {
            SqlConnection con = new SqlConnection(str);
            con.Open();
            SqlCommand cmd = new SqlCommand("select count(*) from test where testid=" + TextBox1.Text.Trim(), con);
            int i = Convert.ToInt32(cmd.ExecuteScalar());
            if (i > 0)
            {
                Label3.Text = "This UserId is already existed";
            }
            else
            {
                Label3.Text = "This User Id not existed";
            }

        }

------------------------------------------------------------------------

2. How to find the last 2 characters in a given input string 

Code behind,


string str=txtinput.Text.Trim().Substring(Math.Max(0,txtinput.Text.Trim().Length-2));

---------------------------------------------------------------------------------

Jul 16, 2014

Some Useful Queries in Sql Server

I. Finding Last Backup Date in SQL Server 2005

select a.name as DBName, coalesce(convert(varchar(12),max(b.backup_finish_date),101),'Not Yet Taken') 
as LastBackupDate,
coalesce(convert(varchar(12),max(b.user_name),101),'NA') as Taken from sys.sysdatabases a
LEFT OUTER JOIN
msdb.dbo.backupset b 
on b.database_name=a.name
group by a.name
order by a.name 
--------------------------------------------

II. List Empty Tables in SQL Server

WITH EmptyRows AS 

  SELECT SUM(row_count) AS [TotalRows], 
         OBJECT_NAME(OBJECT_ID) AS TableName 
  FROM sys.dm_db_partition_stats 
  WHERE index_id = 0 OR index_id = 1 
  GROUP BY OBJECT_ID 

SELECT * FROM EmptyRows 
WHERE [TotalRows] = 0

----------------------------------------------

III. Find the Missing Identity Numbers in SQL Server 2005/2008

WITH Missing (missnum, maxid)
AS
(
SELECT 1 AS missnum, (select max(id) from DebitNote_Attachments)
UNION ALL
SELECT missnum + 1, maxid FROM Missing
WHERE missnum < maxid
)

SELECT missnum
FROM Missing
LEFT OUTER JOIN DebitNote_Attachments tt on tt.id = Missing.missnum
WHERE tt.id is NULL
OPTION (MAXRECURSION 0) 

---------------------------------------------

IV. How to find columns count of any table in any database from sql server

SELECT COUNT(*) FROM .sys.columns
WHERE object_id = OBJECT_ID('..')


-- Ex : 

SELECT COUNT(*) COLUMNCOUNT FROM DBNAME.SYS.COLUMNS
WHERE OBJECT_ID =OBJECT_ID('DBNAME.DBO.TABLE_NAME')

----------------------------------------------

V. How to delete the top 100 row from a table using Sql Server?

WITH CTE AS
(
SELECT TOP 100 *
FROM TABLE_NAME
--ORDER BY a1
)
DELETE FROM CTE

-----------------------------------------------

VI. How to get the row count of all tables in a SQL SERVER

SELECT sc.name +'.'+ ta.name TableName, SUM(pa.rows) RowCnt
FROM sys.tables ta
INNER JOIN sys.partitions pa
   ON pa.OBJECT_ID = ta.OBJECT_ID
INNER JOIN sys.schemas sc
   ON ta.schema_id = sc.schema_id
WHERE  
ta.is_ms_shipped = 0 AND pa.index_id IN (1,0)
GROUP BY 
sc.name,ta.name
ORDER BY 
SUM(pa.rows) DESC

-----------------------------------------------

VII. How to find duplicate records in a table ?

select * from Friends



select Fid, FName, count(Fid) Dups from Friends
group by Fid, FName
having count(Fid)>1
order by Fid



-----------------------------------------------------------------------------------------

VIII. How to generate Row Number in existing table SQL-SERVER

select * from Friends


To generate Row Number,

WITH CTE as (select row_number() over (order by Fid asc) as rowid, * from Friends)
select * from CTE



And we can delete the duplicate records from the table

WITH CTE as (select row_number() over (order by Fid asc) as rowid, * from Friends)
select * from CTE where Fid=2



WITH CTE as (select row_number() over (order by Fid asc) as rowid, * from Friends)
--select * from CTE where Fid=2 // comment this line ...
delete from CTE where rowid=3



WITH CTE as (select row_number() over (order by Fid asc) as rowid, * from Friends)
select * from CTE where Fid=2
--delete from CTE where rowid=3 // comment this line ...




-----------------------------------------------------------------------------------------