netoops blog

Monday, 29 October 2012

How to Create a Duplicate Table with New Name from Existing table programmatically???


Create Table with All Data and same Field Name

SELECT *

INTO [LoginDetailRecreate]

FROM [LoginDetail]


Create Blank Table with Same Field Name

SELECT *

INTO [LoginDetailRecreate]

FROM [LoginDetail]

WHERE 1 = 2



Here, 1=2 will prevent the data from being copyied from LoginDetail to the LoginDetailRecreate table.


Try it

Friday, 26 October 2012

Change Facebook Login Page Background



Facebook Refresh allows you to set a custom image URL as your Facebook homepage wallpaper. You will never have to see the same login page again

To change the background image to one of your own:

#1 – Go to your extensions page chrome://extensions/
#2 – Find the “Facebook Refresh” extension and be sure you are running at least version 1.1.
#3 – Click the “Options” link.
#4 – Enter your image URL in the box and click save.
#5 – Visit Facebook.com (while you are not logged in) and enjoy!

Thursday, 25 October 2012

Dynamic menu in ASP.net

menu_binding.jpg




While working on asp.net project, we will get situation to create a dynamic menu control which will be configurable by admin.

For doing this task we can do like this

Step 1: I have created a table like below





















Step 2: Configure the asp.net menu control like this
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head id="Head1" runat="server">    <title></title>    <style type="text/css">        .menuItem        {            border: Solid 1px black;            width: 100px;            padding: 2px;            background-color: #eeeeee;        }        .menuItem a        {            color: blue;        }        .IE8Fix        {            z-index: 1000;        }    </style></head><body>    <form id="form1" runat="server">    <div>        <asp:Menu ID="Menu1" Orientation="horizontal" StaticMenuItemStyle-CssClass="menuItem"            DynamicMenuItemStyle-CssClass="menuItem" runat="server">            <%– This CSS used for fixing the browser problem with IE8–%>            <DynamicMenuStyle CssClass="IE8Fix" />        </asp:Menu>    </div>    </form></body></html>
Step 3: Write the code for binding asp.net menu on basis of category like this
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using System.Data.SqlClient;using System.Data; 
public partial class _Default : System.Web.UI.Page{    protected void Page_Load(object sender, EventArgs e)    {        if (!IsPostBack)        {            populateMenuItem();        }    }    private void populateMenuItem()    {        DataTable menuData = GetMenuData();        AddTopMenuItems(menuData);    }    private DataTable GetMenuData()    {        using (SqlConnection con = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\Database.mdf;Integrated Security=True;User Instance=True"))        {            using (SqlCommand cmd = new SqlCommand("SELECT Id,ParentId,Name FROM tblProduct", con))            {                SqlDataAdapter da = new SqlDataAdapter(cmd);                DataTable dt = new DataTable();                da.Fill(dt);                return dt;            }        }    }    /// Filter the data to get only the rows that have a    /// null ParentID (This will come on the top-level menu items)    private void AddTopMenuItems(DataTable menuData)    {        DataView view = new DataView(menuData);        view.RowFilter = "ParentID IS NULL";        foreach (DataRowView row in view)        {            MenuItem newMenuItem = new MenuItem(row["Name"].ToString(), row["Id"].ToString());            Menu1.Items.Add(newMenuItem);            AddChildMenuItems(menuData, newMenuItem);        }     }    //This code is used to recursively add child menu items by filtering by ParentID    private void AddChildMenuItems(DataTable menuData, MenuItem parentMenuItem)    {        DataView view = new DataView(menuData);        view.RowFilter = "ParentID=" + parentMenuItem.Value;        foreach (DataRowView row in view)        {            MenuItem newMenuItem = new MenuItem(row["Name"].ToString(), row["Id"].ToString());            parentMenuItem.ChildItems.Add(newMenuItem);            AddChildMenuItems(menuData, newMenuItem);        }    }}

Tuesday, 23 October 2012

Select Query Using Wildcard Characters in SQL Server 2012


The "like" operator is used in a "where" clause to search for a specified pattern of characters using the wildcard mechanism in a column. Wildcard characters make the "like" operator more flexible than using = and != (Not Equal To) string comparison operators. To search for a character string using one or more wildcard characters in a LIKE query, simply include the wildcards in a string literal along with the portion of the string. So let's take a look at a practical example of how to use a like operator to search in SQL Server. The example is developed in SQL Server 2012 using the SQL Server Management Studio.

Wildcard Characters

There are four types of wildcard characters in SQL Server:

  1. Percent sign (%)
  2. Underscore (_)
  3. Bracket ([])
  4. Caret (^)
Creating a Table in SQL Server
The table looks as in the following figure:




Now we perform searching on the above table using wildcard characters.
Like with Percent sign (%)


It is used to search any string of zero or more characters.
Example
SELECT*FROMUserDetailWHEREFirstNameLIKE'ra%' -- return all columns from UserDetail table where FirstName name start with 'ra'

SELECT*FROMUserDetailWHEREFirstNameLIKE'%n'   -- return all columns from UserDetail table where FirstName name End with 'n'

SELECT*FROMUserDetailWHEREFirstNameLIKE'%an%'-- return all columns from UserDetail table where FirstName name have the letters End with 'an'

The result table will show the following information:
Output




Like with Underscore (_)
It is used to search for a single character.
Example
SELECT*FROMUserDetailWHEREFirstNameLIKE'rah_' -- return all columns from UserDetail table where FirstName name is Four characters long and start with 'rah'
SELECT*FROMUserDetailWHEREFirstNameLIKE'_ahu'   -- return all columns from UserDetail table where FirstName name is Four characters long End with 'ahu'
SELECT*FROMUserDetailWHEREFirstNameLIKE'__e'-- return all columns from UserDetail table where FirstName name start and end with any character whereas the middle character must be 'e'.

The result table will show the following information:

Output



Like with Bracket ([])
It is used to search for any single character within the specified range.
Example
SELECT*FROMUserDetailWHEREFirstNameLIKE'[rc]%' -- return all columns from UserDetail table where FirstName name begin with 'R' or 'C'
SELECT*FROMUserDetailWHEREFirstNameLIKE'[rc]%u'  -- return all columns from UserDetail table where FirstName name begin with 'R' or 'C' and end with 'U'.
SELECT*FROMUserDetailWHEREFirstNameLIKE'R[a]%'-- return all columns from UserDetail table where FirstName name begin with 'R' and hold an 'a' in the second place.

The result table will show the following information:

Output



Like with Caret (^)

It is used to search for any single character that is not the specified character.

SELECT*FROMUserDetailWHEREFirstNameLIKE'R[^H]%' -- return all columns from UserDetail table where FirstName name begin with 'R' and does not contain an 'H'  as the second place
SELECT*FROMUserDetailWHEREFirstNameLIKE'%N[^R]'-- return all columns from UserDetail table where FirstName name Contain with 'N' and does not contain an 'R' 

The result table will show the following information:

Output



Monday, 22 October 2012

Visual Studio Keyboard Shortcuts Keys

Shortcut keys play an important role to increase the output. Developers work at least 6 to 8 hours on daily basis on Visual Studio. If the developer knows the shortcut keys, he can keep away from using of mouse and absolutely it will enhance productivity and reduce headache to use of mouse again and again. I am sharing some interesting and useful shortcut keys to work with Visual Studio.

General Shortcut Keys

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

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

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

Thursday, 18 October 2012

Using Multiple Programming Languages in ASP.NET Website



By default, the App_Code folder does not allow multiple programming languages. However, in a Web site project you can modify your folder structure and configuration settings to support multiple programming languages such as Visual Basic and C#. This allows ASP.NET to create multiple assemblies, one for each language. Developers commonly include multiple programming languages in Web applications to support multiple development teams that operate independently and prefer different programming languages.
For this you need to create a separate subfolder in App_Code folder for each of the programming language you want to support in your website. For the purpose of this tutorial I am adding CS and VB subfolders to support C# and Visual Basic source files.
After creating separate subfolders for each programming language, you must change the Web site project configuration so that ASP.NET will compile the subfolders separately. Open the web.config file of the website project and locate <compilation> the section in the file. You need to add the following <codesubdirectories> section inside the <compilation> section.

Add this in web config

<compilation>
  <codeSubDirectories>
    <add directoryName=”CS”/>
    <add directoryName=”VB”/>
  </codeSubDirectories>
</compilation>

Thursday, 11 October 2012

Difference between # and ## in Sql Server



# [Temporary Table]

Ø  The name of this table starts with #.
Ø  Temp table can be accessed within the declared stored procedure.
Ø  The scope of temp table does not exist beyond the stored procedure.
Ø  Temporary table will be dropped automatically on end of each session. 
But it will always be better to drop the table physically using the code
Ø  Temp tables can be created with the same name in multiple windows.
Ø  Different users can create diff temp tables with the same name.
Ø  The tables created will be having a unique id for each session.
Ø  The table name will be appended with the number allocated for that session.
Ø  It will always be better to create indexes on the temp tables and use that within the stored procedures.

Ø  Any procedure with a temporary table cannot be pre-compiled
CREATE TABLE #Temp_TestTable
([TestTableID] [int] NOT NULL,
 [FirstCol] [varchar](200) NULL,
 [SecondCol] [int] NULL
)
GO

DROP TABLE #Temp_TestTable
GO

## [Global Temporary Table]
Ø  The name of this table will be started with ##.
Ø  Global temp table can be accessed across the sessions.
Ø  You can create the table in stored procedure and can use this across multiple stored procedures.
Ø  Global temp tables are created with the same name given by the user.
Ø  These are just like simple temporary tables but are available to all sessions and will only be dropped automatically when last session of database will be closed. If single session is active, global temporary tables will remain available.


CREATE TABLE ##GTemp_TestTable
([TestTableID] [int] NOT NULL,
 [FirstCol] [varchar](200) NULL,
 [SecondCol] [int] NULL
)
GO


DROP TABLE ##GTemp_TestTable   
GO

Friday, 5 October 2012

Timing Operations in Visual Studio 2012

using System;
using System.Linq;
using System.Windows.Forms;
using System.Diagnostics;
 
namespace SpeedTest
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
 
            // set up the labels for the initial load
            lblTest1.Text = "Test 1:  Waiting...";
            lblTest2.Text = "Test 2:  Waiting...";
 
            // display whether or not the stop watch
            // supports high resolution counters
            if (Stopwatch.IsHighResolution)
                lblHighPrec.Text = "Stopwatch is high precision";
            else
                lblHighPrec.Text = "Stopwatch is not high precision";
        }
 
        private void btnTest_Click(object sender, EventArgs e)
        {
            // create a new instance of stopwatch and start it
            Stopwatch sw1 = new Stopwatch();
            sw1.Start();
            // run the task
            RunTest1();
            //stop the stop watch
            sw1.Stop();
           
            // display the time required by the task to complete
            lblTest1.Text = "Test 1:  Elapsed time was "
                + sw1.Elapsed.Milliseconds.ToString() + " msec";
           
            // repeat the steps with the second task
            // so we can compare times
            Stopwatch sw2 = new Stopwatch();
            sw2.Start();
            RunTest2();
            sw2.Stop();
 
            lblTest2.Text = "Test 2:  Elapsed time was "
                + sw2.Elapsed.Milliseconds.ToString() + " msec";
           
        }
 
 
        /// <summary>
        /// Meaningless test 1
        /// </summary>
        public void RunTest1()
        {
            lblTest1.Text = "Test 1:  Running...";
 
            for (int i = 0; i < 100000; i++)
            {
                int test = int.Parse("105532");
            }
        }
 
 
        /// <summary>
        /// Meaningless test 2
        /// </summary>
        public void RunTest2()
        {
            lblTest2.Text = "Test 2:  Running...";
 
            for (int i = 0; i < 100000; i++)
            {
                int test = Convert.ToInt32("105532");
            }
        }
 
 
        private void btnExit_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
    }
}
Related Posts Plugin for WordPress, Blogger...