Saturday, 9 March 2013

Disable cut , copy and paste on page in Asp.net using scripting:

Disable cut , copy and paste on page in Asp.net using scripting:::

Just follow the steps below:

1. Put : 

<script type="text/javascript">

2. Inside block script put $(document).ready(function() function

<script type="text/javascript">

$(document).ready(function() {

3. Can bind for cut , copy , paste for event handler to target textbox

<script type="text/javascript">

$(document).ready(function() {

$('#<%=txtTarget.ClientID%>').bind('cut copy paste', // ClinetID properties : Gets the control ID for HTML markup that is generated by ASP.NET

4. Prevent behavior that include "copy, cut, paste " for this textbox

<script type="text/javascript">

$(document).ready(function() {

$('#<%=txtTarget.ClientID%>').bind('cut copy paste',

function(e) { e.preventDefault(); // default behavior disable

5. Showing alert that cut , copy , pastecut , copy , paste is disabled!

<script type="text/javascript">

$(document).ready(function() {

$('#<%=txtTarget.ClientID%>').bind('cut copy paste',

function(e) { e.preventDefault();

alert("cut , copy , paste disable !!!!!");

});

});

</script>

Disable Back Button Of Browser in Asp.net:

Disable Back Button Of Browser in Asp.net:::

wriite this code in Head Tag of Default.aspx page ::
<script type="text/javascript">
function disablebackButton()
{
window.history.forward(0);
}
setTimeout("disablebackButton()",0);

</script>

and write this code in in a Body Tag as a attribute of Body Tag:::

<body onload="disablebackButton()">

Thursday, 28 February 2013

Finding the 2 nd Highest salary in Sql server


USE Mydb
GO

--creating the table

CREATE TABLE EMP
(
ID INT IDENTITY(1,1)
CONSTRAINT PK_EMP_ID  PRIMARY KEY,
NAME VARCHAR(30) NOT NULL,
SALARY MONEY
)
------To view the structure of the table


SELECT * FROM EMP











----Insert the records into the table

INSERT INTO EMP VALUES ('PRAMOD',12000),
('HARISH',15000),
('NARENDRA',20000),
('KRISHNA',15000),
('KIRAN',23000),
('RAMU',16000)

----FINDING THE TOP 2 nd Highest salary 
SELECT TOP 1  *
FROM EMP WHERE SALARY IN( SELECT TOP 2 SALARY
FROM EMP
ORDER BY 1 DESC)
ORDER BY SALARY asc














-----TOP 4 TH SALARY 

SELECT TOP 1  *
FROM EMP WHERE SALARY IN( SELECT TOP 4 SALARY
FROM EMP
ORDER BY 1 DESC)
ORDER BY SALARY asc




Wednesday, 27 February 2013

JOINS



Joins: by using the join ,we can retrieve the data from two or more tables based on logical relationships
between the tables.


The joins allow you to view data from related tables in a single result set.we can join the more
 then one table based on a common attribute


     depending on the requirements to view data from multiple tables,we can apply the different types of joins,such
     as inner join,outer join,cross join,self join

INNER JOIN:
------------  

        An inner join retrieves the records from multiple tables after comparing the values present in a common column.when inner
join is applied ,only the rows which values satisfying the join condition  in the common column are displayed.
The rows in both the tables that do not satisfy the join condition are not displayed.

 ex:   SELECT EMP.EMPID,EMP.NAME,EMP.SAL,EPH.PHONE_NUM
FROM EMPLOYEE EMP
JOIN EMP_PHONE_NUM EPH
ON EMP.EMPID=EPH.EMPID

OUTER JOIN:
-----------

An outer join displays the result set containing all the rows from one table and matching rows from the other table.


 for example.if we create an outer join on table A and table B ,it will show you all the records of table A and only
those records from table B for which the condition on the common column holds true..


An outer join displays NULL for the columns of the related table where it does not find any matching records .
AN outer join is the following types:
1.Left outer join.
2.Right outer join.
3.Full outer join.

1.LEFT OUTER JOIN:
-------------------
THE LEFT outer join returns the all the rows from the table specified on the left side of the LEFT OUTER JOIN
keyword and the matching rows from  the table specified on the right side .it displays NULL  for the columns of the
 table specified on the right side where it does not find any matching records


EX:SELECT EMP.EMPID,EMP.NAME,EMP.SAL,EPH.PHONE_NUM
FROM EMPLOYEE EMP
LEFT OUTER JOIN EMP_PHONE_NUM EPH
ON EMP.EMPID=EPH.EMPID

2.RIGHT OUTER JOIN:
-------------------
  THE right outer join returns the all the rows from the table specified on the right side of the RIGHT OUTER JOIN
keyword and the matching rows from  the table specified on the left side .it displays NULL  for the columns of the
 table specified on the left side where it does not find any matching records


ex: SELECT EMP.EMPID,EMP.NAME,EMP.SAL,EPH.PHONE_NUM
FROM EMPLOYEE EMP
RIGHT OUTER JOIN EMP_PHONE_NUM EPH
ON EMP.EMPID=EPH.EMPID

 

 3.FULL OUTER JOIN:
-------------------
A full outer join is the combination of left outer join and right outer join.This join returns all the matching and
non-matching rows from the both the tables.
the matching records are displayed only once .In case of non-matching rows,a NULL value is displayed
for the columns for the columns for which data is not available.




ex:SELECT EMP.EMPID,EMP.NAME,EMP.SAL,EPH.PHONE_NUM
FROM EMPLOYEE EMP
FULL OUTER JOIN EMP_PHONE_NUM EPH
ON EMP.EMPID=EPH.EMPID

CROSS JOIN: A cross join is also known as a Cartesian Product .it join each row of one table with each row of the other table


      The number of rows in the result set equal to the number of rows in the first table multiplied by the number of rows
in the second table


ex:SELECT A.NAME,A.SAL,B.PHONE_NUM
FROM EMPLOYEE A
CROSS JOIN EMP_PHONE_NUM B


SELF-JOIN:  A self join, a table is  joined with itself .As a result,one row in the table correlates with other rows in the
---------   same table.


ex:SELECT E.ID,E.NAME,D.DEPT_NO
FROM EMP E
JOIN EMP D
ON E.ID=D.ID






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



                     

Tuesday, 26 February 2013

PRINT THE DIV USING THE JAVA SCRIPT



<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default8.aspx.cs" Inherits="Default8" %>

<!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 runat="server">
    <script type="text/javascript">
        function PrintDiv() {
            var divToPrint = document.getElementById('divToPrint');
            var popupWin = window.open('', '_blank', 'width=300,height=300');
            popupWin.document.open();
            popupWin.document.write('<html><body onload="window.print()">' + divToPrint.innerHTML + '</html>');
            popupWin.document.close();
        }
    </script>
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div id="divToPrint">
        <h1>
            hai i am printing the Div
        </h1>
    </div>
    <div>
        <input type="button" value="print" onclick="PrintDiv()" />
    </div>
    </form>
</body>
</html>

Monday, 25 February 2013

STORED PROCEDURES



Stored procedure:
------------------
Stored procedures are special objects available in sql server. Its a precompiled statements where all
the preliminary parsing operations are performed and the statements are ready for execution.

Its very fast when compared to ordinary sql statements where the sql statements will undergone a sequence of steps to
fetch the data

Stored procedure involves various syntax based on the parameters passed.
Let me show you a generic syntax for a stored procedure.



create procedure proc_name
as
begin

sql statement1
sql statement2
end


ex:2

create procudere getempproc
as
begin
select * from employee

end




creating the parameterized stored procedures:
---------------------------------------------

we want to execute a procedure for a different values of a variable that are provided
at run time.for this we can create the parameterized stored procedures


the parameters are used to pass values to the stored procedure during run time.


USE  test1
GO

IF EXISTS (SELECT 1 FROM SYS.OBJECTS WHERE [TYPE] = 'P' AND NAME = 'GetMarks')

DROP PROCEDURE GetMarks

GO

CREATE PROCEDURE GetMarks

(

@m1 int=0,

@m2 int=0,

@m3 int=0,

@m4 int=0,

@m5 int=0,

@m6 int=0

)
AS
BEGIN

DECLARE @Tot INT,
DECLARE @Avg FLOAT,

SELECT @Tot = @m1+@m2+@m3+@m4+@m5+@m6,
@avg=@Tot/6
if(@m1>=35&& @m2>=35&& @m3>=35&& @m4>=35 && @m5>=35 && @m6>=35)
BEGIN
PRINT 'pass'
if(@avg>=90)
PRINT 'first division'
else


if(@avg>=75)
PRINT 'second division '
else

if(@avg>=35)

PRINT 'third division '
else

PRINT 'fail'

END
END


by  ushing the stored procedure we can insert the elements into the table
ex:


TABLE1:


IF NOT EXISTS(SELECT * FROM SYS.OBJECTS WHERE name = 'Student_Detail' AND [type] = 'U')
BEGIN
CREATE TABLE Student_Detail
(
StudentId INT IDENTITY(1,1)
CONSTRAINT [PK_Student_Detail_StudentId] PRIMARY KEY,
FirstName VARCHAR(75) NOT NULL,
LastName VARCHAR(25) NOT NULL,
DOB DATETIME NOT NULL,
)
END
GO

TABLE2:


IF NOT EXISTS(SELECT * FROM SYS.OBJECTS WHERE name = 'Cource' AND [type] = 'U')
BEGIN  
CREATE TABLE Cource
(
CourceId int IDENTITY(100,10)
CONSTRAINT [PK_Cource_CourceId] PRIMARY KEY,
Cource_Code VARCHAR(10) ,
CourceName VARCHAR(25) NOT NULL

)

END

TABLE3:


IF NOT EXISTS(SELECT * FROM SYS.OBJECTS WHERE name = 'CITY' AND [type] = 'U')
BEGIN
CREATE TABLE CITY
(CityId INT IDENTITY(600,1)
CONSTRAINT [PK_CITY_CityId] PRIMARY KEY,
CityCode VARCHAR(10) ,
CityName VARCHAR(50))
END







TABLE4:


IF NOT EXISTS(SELECT * FROM SYS.OBJECTS WHERE name = 'STUDENT_CITY' AND [type] = 'U')
BEGIN
CREATE TABLE STUDENT_CITY
(
StudentCityId INT IDENTITY(111,110)
                CONSTRAINT PK_STUDENT_CITY_StudentCityId PRIMARY KEY,
                StudentId INT
                                     CONSTRAINT [FK_STUDENT_CITY_StudentId]  FOREIGN KEY(StudentId)            REFERENCES Student_Detail(StudentId),
CityId INT CONSTRAINT FK_STUDENT_CITY_CityId FOREIGN KEY(CityId)
REFERENCES CITY(CityId)

)
END

TABLE5:



IF NOT EXISTS(SELECT * FROM SYS.OBJECTS WHERE name = 'STUDENT_COURCE' AND [type] = 'U')
BEGIN
CREATE TABLE STUDENT_COURCE
(
StudentCourceId INT IDENTITY(1,1)
CONSTRAINT PK_STUDENT_COURCE_StudentCourceId PRIMARY KEY,
StudentId INT CONSTRAINT [FK_STUDENT_COURCE_StudentId] FOREIGN KEY(StudentId) REFERENCES Student_Detail(StudentId),
CourceId INT CONSTRAINT  [FK_STUDENT_COURCE_courceId] FOREIGN KEY (CourceId) REFERENCES Cource(CourceId)
)


END

HERE FIVE TABLES ARE THERE BY USHING THE STORED PROC WE WILL UPDATE THE ALL THE TABLES



Use VENKAT
GO

IF EXISTS (SELECT 1 FROM SYS.OBJECTS WHERE [TYPE] = 'P' AND NAME = 'SetStudentDetails')
DROP PROCEDURE SetStudentDetails

CREATE  PROCEDURE SetStudentDetails     
(
@firstname VARCHAR(75),
@lastname VARCHAR(25),
@dob DATETIME,
@cource VARCHAR(25),          
@city VARCHAR(50)
)
 
AS
/*******************************************************
CREATED BY :
CREATED DATE : 5//2012
DESC : procedure to SetStudentDetails   
CHANGE HISTORY
NAME DATE DESC

USAGE:
EXEC SetStudentDetails 'NARI','A','1989-03-15','MBA','KHAMMAM'

********************************************************/
SET NOCOUNT ON
BEGIN
DECLARE @StudentIdentity INT
IF NOT EXISTS(SELECT * FROM Student_Detail WHERE  FirstName = @firstname AND LastName = @lastname AND DOB = @dob)
INSERT INTO Student_Detail(
FirstName,
LastName,
DOB
)
VALUES
(
@firstname,
@lastname,
@dob
)
SELECT @StudentIdentity = @@IDENTITY
DECLARE @CourceIdentity INT, @CityIdentity INT
IF NOT EXISTS(SELECT * FROM Cource WHERE  CourceName= @cource)

INSERT INTO Cource
(
Cource_Code,
CourceName
)
VALUES
(
Left (@cource,3),
@cource
)

SELECT @CourceIdentity = CourceId  FROM Cource WHERE  CourceName= @cource
IF NOT EXISTS(SELECT * FROM CITY WHERE CityName = @city)

INSERT INTO  CITY
(
CityCode,
CityName
)
VALUES
(
Left(@city, 4),
@city
)

SELECT @CityIdentity = CityID FROM CITY WHERE CityName = @city
IF NOT EXISTS(SELECT * FROM student_cource WHERE StudentId =@StudentIdentity )

INSERT INTO student_cource
(
StudentId,
CourceId 
)
vALUES
(
@StudentIdentity,
@CourceIdentity                     
)

DECLARE @StudentCourceId INT 
SELECT @StudentCourceId = @@IDENTITY
IF NOT EXISTS(SELECT * FROM STUDENT_CITY WHERE StudentId=@StudentIdentity )
INSERT INTO STUDENT_CITY
(

StudentId,
CITYID
)
vALUES
(

@StudentIdentity,
@CITYIdentity
)

END






EX2:



USE VENKAT
GO


IF EXISTS(SELECT * FROM SYS.OBJECTS WHERE TYPE='P' AND NAME='GetStudentDetails')
DROP PROCEDURE GetStudentDetails
GO


CREATE PROCEDURE GetStudentDetails
(
@StudentID INT
)
AS
/*******************************************
Author    : 
Date      : 05/01/2012
Desc      : Procedure to get Student Details
Usage     : EXEC GetStudentDetails 1
Change History :
Name        Date         Description

********************************************/
SET NOCOUNT ON
BEGIN
IF EXISTS(SELECT * FROM Student_Detail WHERE StudentID = @STUDENTID)
SELECT SD.StudentID,
SD.FirstName,
SD.LastName,
SD.DOB,
CR.CourceId,
CR.Cource_Code,
CR.CourceName,
C.CityID,
C.CityCode,
C.CityName
FROM Student_Detail SD
INNER JOIN Student_City SC
ON SC.StudentID = SD.StudentID
INNER JOIN City C
ON C.CityID = SC.CityID
INNER JOIN STUDENT_COURCE SCR
ON SCR.StudentID = SD.StudentID
INNER JOIN Cource CR
ON CR.CourceId = SCR.CourceId
WHERE SD.StudentID = @StudentID

ELSE
BEGIN
PRINT 'THIS ID IS NOT EXISTS...THERE IS NO STUDENT' 
END

END










DATA TYPES IN SQL


DATA TYPES:
-----------
Data type represent the type of the data that a database object contain.
this data can be in the form of charecters or numbers.


INT
---
stores  onley the integer data
(whole numbers)


range: 2^31-1(2,147,483,647)



smallint:
---------
stores onley the integer values

range:2^15-1(32,767)



money:
-----
stores onley the money data

range:922,337,203,685,477.5808 to 922,337,203,685,477.5807



Datetime:
---------

stores  onley date and time data

range:
january 1,1753 through december 31,9999

time:
----
it accepts onley the Time data

range: 00:00:00:000000 through
23:59:59:9999999


char(n):
--------
it accepts 'n' charecters ,where n can be 1 to 8000
fixed  lengh charecter data

varchar(n)
-----------
it is used to store Variable length character data

n charecters,where n can be 1 to 8000

BINARY:
------
It is used to store Fixed length binary data

maximum length of 8000 bytes


Varbinary:
----------
It is used to store  variable length binary data

maximum length of 8000 bytes.

nvarchar:
---------
it is used to store the variable length Unicode data

max length of 4000 charecters.
©chantidodda