Tuesday, September 25, 2012

Find selected item from radiobutton list using javascript

ASP.NET renders a table and a bunch of other mark-up around the actual radio inputs  

 var list = document.getElementById("rdbdesc"); 
    var inputs = list.getElementsByTagName("input"); 
    var selected;  
    for (var i = 0; i < inputs.length; i++)  
    {      
    if (inputs[i].checked) { 
    selected = inputs[i];     
    break;   
    }    
    }   
    if (selected)
    {
       
    alert(selected.value);   
   
    }
  

Difference Between the HAVING and WHERE Clauses in a SQL

Difference Between the HAVING and WHERE Clauses in a SQL
  1. The WHERE clause specifies the criteria which individual records must meet to be selcted by a query. It can be used without the GROUP BY clause. The HAVING clause cannot be used without the GROUP BY clause.
  2. The WHERE clause selects rows before grouping. The HAVING clause selects rows after grouping.
  3. The WHERE clause cannot contain aggregate functions. The HAVING clause can contain aggregate functions. source

    Using the code

    Code
    1. SELECT cusnum, lstnam, init
    2. FROM Test
    3. WHERE state IN ('CA', 'LA')
    4.  
    5. CUSNUM LSTNAM INIT BALDUE
    6. ====== ============ ==== ========
    7. 938472 John G K 37.00
    8. 938485 Mark J A 3987.50
    9. 593029 Lily E D 25.00
    Suppose I want the total amount due from customers by state. In that case, I would need to use the GROUP BY clause to build an aggregate query.
    Code
    1. SELECT state,SUM(baldue)
    2. FROM Test
    3. GROUP BY state
    4. ORDER BY state
    5.  
    6. State Sum(Baldue)
    7. ===== ===========
    8. CA 250.00
    9. CO 58.75
    10. GA 3987.50
    11. MN 510.00
    12. NY 589.50
    13. TX 62.00
    14. VT 439.00
    15. WY .00
    Using Having
    Code
    1. SELECT state,SUM(baldue)
    2. FROM Test
    3. GROUP BY state
    4. HAVING SUM(baldue) > 250
    5.  
    6.  
    7. State Sum(Baldue)
    8. ===== ===========
    9. GA 3987.50
    10. MN 510.00
    11. NY 589.50
    12. VT 439.00




Monday, September 24, 2012

Get All Running Instances of Sql Server

Que:- Get All Running Instances of Sql Server?

Sol:-

Step 1. add Com refrence to  sqlserver dmo.

sqldmo.dll can be found at
"C:\Program Files\Microsoft SQL Server\80\Tools\Binn\SQLDMO.DLL"

Step 2.add this code in page_load event

protected void Page_Load(object sender, EventArgs e)
    {
        NameList sqlservers = new SQLDMO.Application().ListAvailableSQLServers();
       
        foreach (string sql in sqlservers )
           {
                Response.Write(sql +"<br/>");
           }
    }

Access an asp.net website using IP Address in an LAN Network

step 1:

Click on Start--> Run-->type in textbox 'Inetmgr', to open IIS .

step 2:

click on Websites-->Default Websites --> YourWebApplicationName

browse through your application virtual directory.

step 3.
right click on WebApplication and select PROPERTIES.

click on 'Directory Security' Tab

step 4.

In 'Anonymous Access and Authentication Control' click on EDIT .

step 5.

Check the checkbox 'Anonymous Access' and uncheck remaining all
(except Allow IIS to control password, Let it be checked)

step 6.

Click Ok. again OK.

Step 7.

now open control panel-->Windows Firewall

step 8.

click on Exceptions Tab.

step 9.

Click on Add Port. Enter Name: IIS and Port Number : 80 Click Ok.again
Click OK.

step 10.

now open IE and enter your system IP : http://192.168.X.X/

Friday, September 21, 2012

Check given Year is Leap year or Not in Sql Server?

create function dbo.fn_IsLeapYear (@year int)
returns bit
as
begin
return(select case datepart(mm, dateadd(dd, 1, cast((cast(@year as varchar(4)) + '0228') as datetime)))
when 2 then 1
else 0
end)
end
go


Get Paging Data from Sql Server

Why Custom Paging?
Custom paging allows you to get limited number records from a large database table that saves processing time of your database server as well as your application server and makes your application scalable, efficient and fast.

In this article, I am going to explain how to create a stored procedure in SQL Server 2005 that allows you to pass startRowIndex and pageSize as a parameter and return you the number of records starting from that row index to the page size specified. It was possible in the SQL Server 2000 too but it was not as easy as in SQL Server 2005 is.

-- EXEC LoadPagedArticles 10, 5CREATE PROCEDURE LoadPagedArticles 
-- Add the parameters for the stored procedure here
@startRowIndex int,
@pageSize int
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- increase the startRowIndex by 1 to avoid returning the last record again SET @startRowIndex = @startRowIndex + 1
BEGIN
SELECT * FROM (
Select *,
ROW_NUMBER() OVER (ORDER BY registration_no ASC) as RowNum
FROM grievance
) as grievance
WHERE RowNum BETWEEN @startRowIndex AND (@startRowIndex + @pageSize) - 1
ORDER BY registration_no ASC
END
END
GO

Run It:-

exec LoadPagedArticles 6,5


Get Comma Delimited List in Sql Server

How Get Comma Delimited List in Sql Server?

Solution:- 

DECLARE @state_name nvarchar(100)
SELECT @state_name = COALESCE(@state_name,'') + COALESCE(state_name,'') + ',' FROM states
WHERE state_name IS NOT NULL
SET @state_name = SUBSTRING(@state_name,0,LEN(RTRIM(@state_name)))
--use for print list 
PRINT @state_name

Example:-



 

Search within Database in any Table

How To search entire database?

here is how you run it:

--To search all columns of all tables in Pubs database for the keyword "Computer"
EXEC SearchAllTables 'Computer'
GO


Here is the complete stored procedure code:


CREATE PROC SearchAllTables
(
 @SearchStr nvarchar(100)
)
AS
BEGIN

 -- Copyright © 2002 Narayana Vyas Kondreddi. All rights reserved.
 -- Purpose: To search all columns of all tables for a given search string
 -- Written by: Narayana Vyas Kondreddi
 -- Site: http://vyaskn.tripod.com
 -- Tested on: SQL Server 7.0 and SQL Server 2000
 -- Date modified: 28th July 2002 22:50 GMT


 CREATE TABLE #Results (ColumnName nvarchar(370), ColumnValue nvarchar(3630))

 SET NOCOUNT ON

 DECLARE @TableName nvarchar(256), @ColumnName nvarchar(128), @SearchStr2 nvarchar(110)
 SET  @TableName = ''
 SET @SearchStr2 = QUOTENAME('%' + @SearchStr + '%','''')

 WHILE @TableName IS NOT NULL
 BEGIN
  SET @ColumnName = ''
  SET @TableName = 
  (
   SELECT MIN(QUOTENAME(TABLE_SCHEMA) + '.' + QUOTENAME(TABLE_NAME))
   FROM  INFORMATION_SCHEMA.TABLES
   WHERE   TABLE_TYPE = 'BASE TABLE'
    AND QUOTENAME(TABLE_SCHEMA) + '.' + QUOTENAME(TABLE_NAME) > @TableName
    AND OBJECTPROPERTY(
      OBJECT_ID(
       QUOTENAME(TABLE_SCHEMA) + '.' + QUOTENAME(TABLE_NAME)
        ), 'IsMSShipped'
             ) = 0
  )

  WHILE (@TableName IS NOT NULL) AND (@ColumnName IS NOT NULL)
  BEGIN
   SET @ColumnName =
   (
    SELECT MIN(QUOTENAME(COLUMN_NAME))
    FROM  INFORMATION_SCHEMA.COLUMNS
    WHERE   TABLE_SCHEMA = PARSENAME(@TableName, 2)
     AND TABLE_NAME = PARSENAME(@TableName, 1)
     AND DATA_TYPE IN ('char', 'varchar', 'nchar', 'nvarchar')
     AND QUOTENAME(COLUMN_NAME) > @ColumnName
   )
 
   IF @ColumnName IS NOT NULL
   BEGIN
    INSERT INTO #Results
    EXEC
    (
     'SELECT ''' + @TableName + '.' + @ColumnName + ''', LEFT(' + @ColumnName + ', 3630) 
     FROM ' + @TableName + ' (NOLOCK) ' +
     ' WHERE ' + @ColumnName + ' LIKE ' + @SearchStr2
    )
   END
  END 
 END

 SELECT ColumnName, ColumnValue FROM #Results
END
 
 
Ref:- 

Tuesday, September 18, 2012

JQuery Toggle Example


Toggling using J Query to Show/Hide Div

Steps.-
1. <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.js"></script>
    add this line in your code for j Query Library.
2.
<input type="submit" id="xyz" value="Check Toggle" >

        <div id="dv1" style="color:#ff1493;">
         a journey over toggle function in jquery. <br/>
           This is a demo. <br/>
           in this demo dive section is toggle on button click event in different type of animation.
        </div>
        <script src ="jquery.js"></script>

        <script>
            $('#xyz').click( function aditya()
            {
                $('#dv1').slideToggle().delay(1000);
            }
            )

        </script>

see Video






Monday, September 17, 2012

Visual Studio 2010 Shortcuts

Visual Studio 2010 Shortcuts  


1. Manage Visual Studio
Ctrl+s Save current file
Ctrl+Shift+s Save all files
Ctrl+Shift+n Create new project
Ctrl+o Open file
Ctrl+Shift+o Open project
Ctrl+Shift+a Add item to project
Esc Close menu or dialog
Ctrl+p Print
Shift+Alt+Enter Toggle full screen mode
Ctrl+f4 Close current tab
Ctrl+f6/Ctrl+Shift+f6 Go to next / go to previous window
Ctrl+Tab, then Arrow keys Press and hold Ctrl+Tab, then using arrow keys gives a small task manager with all open files and views

2. Bookmarks
For keystrokes with two keys such as Ctrl+k+k, keep holding the Ctrl key until releasing the last key.
Ctrl+k+k Toogle bookmark
Ctrl+k+n Goto next bookmark
Ctrl+k+p Goto previous bookmark
Ctrl+Shift+k+n Goto next bookmark in folder
Ctrl+Shift+k+p Goto previous bookmark in folder
Ctrl+k+w Put focus on bookmark window
Esc Leave bookmark window and focus on editor
Ctrl+k+h Toggle code shortcut at current line*
Ctrl + K + L Clear all bookmarks
*if somebody figures out additional shortut keys on how to use code shortcuts, please edit this page and add.

3. Code Editor
Find, Replace, and Goto
Ctrl+f Find and replace dialog box
f3/Shift+f3 Find next / find previous
Ctrl+h Display Replace options on the quick tab
Shift+f12 Find all references for selected symbol
Ctrl+Shift+f Find in files
Alt+F3, s Stop current find in files operation
Ctrl+F3/Ctrl+Shift+f3 Find next / find previous in selected text
Alt+F12 Find symbol
Ctrl+d Put cursor in find/command box of the toolbar. Use ctrl+/ in Visual C#
Ctrl+i/Ctrl+Shift+i Incremental search / reverse incremental search
Shift+Alt+f12 Quick find symbol
Ctrl+, Display Navigate-To dialog box
Ctrl+g Goto line number
Ctrl+] Go to matching brace in source file
 
Undo, Redo, Copy, Paste
Ctrl+x, Ctrl+x, Ctrl+v Cut, copy, paste
Ctrl+Shift+v Pastes an item from the Clipboard ring
Ctrl+z Undo
Ctrl+y Redo (or Shift+Alt+Backspace, or Ctrl+Shift+Z)
 
Select Text
Shift+Arrow Keys Extend selection one character/one line
Ctrl+Shift+End/ Ctrl+Shift+Home Extend selection to end / to beginning of document
Ctrl+Shift+] Extend selection to nexst brace
Shift+End/ Shift+Home Extend selection to end / to beginning of line
Shift+Page Down/ Shift+Page Up Extends selection down one page / up one page
Ctrl+w Select current word
Esc Cancel Selection
Ctrl+Shift+Page Down/ Page Up Moves cursor and extend selection to the last line / first line in view.
Ctrl+Shift+Arrow right/ arrow left Extend selection one word to the right / one word to the left
Ctrl+a Select All
 
4. Coding
Collapse Items
Ctrl+m+m Collapse / un-collapse current preset area (e.g. method)
Ctrl+m+h Collpase / hide current selection
Ctrl+m+o Collapse declaration bodies
Ctrl+m+a Collapse all
Ctrl+m+x Uncollapse all
Ctrl+m, ctrl+t Collapse Html tag
Edit Code
Ctrl+l Delete current line or selection of lines to and add to clipboard
Ctrl+Shift+l Delete current line or selection of lines
Ctrl+Delete Delete word to right of cursor
Ctrl+Backspace Delete word to left of cursor
Ctrl+Enter Enter blank line above cursor
Ctrl+Shift+Enter Enter blank line below cursor
Ctrl+Shift+u Make uppercase
Ctrl+u Make lowercase (reverse upercase)
Ctrl+k+c Comment selected text
Ctrl+k+u Uncomment selected text
Ctrl+k+\ Remove white space and tabs in selection or around current cursor position
Ctrl+k+d Format document to code formatting settings
Ctrl+k+f Format selection to code formatting settings
Ctrl+Shift+space Display parameter required for selected method
Ctrl+Shift+8 Visualize whitespace (or press Ctrl+r, then Ctrl+w)
Ctrl+k+d Format document to code formatting settings
Ctrl+k+f Format selection to code formatting settings
Ctrl+Shift+t Transpose word to right of cursor; makes b=a out of a=b if cursor was in front of a
Ctrl+t Transpose character left and right of cursor; cursor between ab would make ba
Shift+Alt+t Transpose line: Move line below cursor up and current line down.
IntelliSense and Code Helper
Ctrl+Space Autocomplete word from completion list (or alt+right arrow)
Ctrl+Shift+Space Show parameter info
Ctrl+f12 Display symbol definition
f12 Display symbol declaration
Ctrl+j Open IntelliSense completion list

5. Build and Debug
f7 Build solution (or Ctrl+shift+b)
Ctrl+Alt+f7 Rebuild solution
Ctrl+break Cancel build process
Ctrl+\+e Show error list
f9 Toggle breakpoint
Ctrl+b Insert new function breakpoint
f5 Start debugging
f11 Debug / step into
f10 Debug / step over
Shift+f11 Debug / step out
Ctrl+f10 Debug / run to cursor
Ctrl+Alt+q Show Quickwatch window
Ctrl+Shift+f10 Set current statement to be the next executed
Alt+* (on numeric keyboard) Show nexst statement
Ctrl+Alt+e Show Exception dialog box
Ctrl+f11 Toggle between disassembly and user code view
Shift+f5 Stop Debugging
Ctrl+f5 Bypass debugger
Ctrl+Alt+p Show attach to process window
Ctrl+Alt+break Break all executing threads                                
 
6. Tool Windows
Ctrl+/      Put cursor in the find/command box in toolbar
Ctrl+k+b      Open code snippet manager window
Alt+f11      Open macro IDE window
Ctrl+k+w      Open bookmark window
Ctrl+Alt+k      Open call hierarchy window
Ctrl+Shift+c      Open class view window
Ctrl+Alt+a      Open Command window
Ctrl+Shift+o      Open Output window
Ctrl+Shift+e      Open Resource view window
Ctrl+Shift+s      Open Server explorer window
Ctrl+Shift+l      Open Solution explorer window
Shift+Esc      Close Find & Replace Window

Tuesday, September 11, 2012

Add /Remove controls on Multple Select Option using JavaScript

Add /Remove  controls on Multple Select Option using JavaScript
<script language="javascript">

    function loopSelected()
    {
          var PIOID = document.getElementById('PIOID');
        var ExistingControl1='';
        var selectedArray = new Array();
        var selObj = document.getElementById('selMulPio');
        var i;
        var count = 0;
        for (i=0; i<selObj.options.length; i++) {
                if (selObj.options[i].selected) {
                    ExistingControl1=ExistingControl1+"<textarea id='txt"+i+"'></textarea>";
                                 }
        }
            PIOID.innerHTML=null;   
            PIOID.innerHTML = ExistingControl1;

    }
</script>

<select name="pio[]"  id="selMulPio"  multiple="multiple"  style="width:100px; height:120px;" onchange="loopSelected();">
<option value="1">India</option>
<option value="2">USA</option>
<option value="3">PAK</option>
</select>
<br>
<div id="PIOID"></div>


=================================
example:-
=================================