This asp.net example article will Demonstrates you how to Dynamically set a link to a CSS file in ASP.NET .For Dynamically set a link to a CSS file in ASP.NET follow the below steps.
1-For Dynamically set a link
add a runat attribute to your traditional link tag this
tag must have its ID attaribute present.
<head>
<link id="MyCSSSheet" rel="stylesheet"
type="text/css" runat="server" />
</head>
2-Now in your content page
Page_Load event , add the "href" attribute of the link tag as
below.
protected void Page_Load(object
sender, EventArgs e)
{
if
(!Page.IsPostBack)
{
MyCSSSheet.Attributes.Add("href","path
of Css file");
}
}
If you have a website that has master and content pages and you want to add some javascript code
on content page which will run when page is loaded then add this code to your content page code
behind pageload event.
Here you watch how do i get javascript run from content page.
In the above Asp.Net Example if you register more than one script in this way, there is no guarantee in which order they will be executed, if you want to control the order of execution, you can combine all into one script in proper order and register them as one script.
Here you watch how do i get javascript run from content page.
protected void Page_Load(object sender, EventArgs e)
{
Type PageType = GetType();
const string YourscriptName = "Popup";
if (!ClientScript.IsStartupScriptRegistered(PageType ,YourscriptName ))
{
ClientScript.RegisterStartupScript(PageType , YourscriptName, "alert('Hello !')",
true);
}
}
In the above Asp.Net Example if you register more than one script in this way, there is no guarantee in which order they will be executed, if you want to control the order of execution, you can combine all into one script in proper order and register them as one script.
In this article I am going to explain how you can find nth highest salary of the employee in SQL Server.
It is very common question asked by interviewer that how to find 2nd highest salary of employee or how to find 3rd highest salary of employee or how to find nth highest salary of employee in SQL Server. Here in this Sql Server Query Example i will Show you how to find 2nd,3rd,4th,.......,nth highest salary of employee.For this sql server query example i have created a Temporary Sql server Table in Sql Server Database named #EmpDetails .And enterd some values to this sql server table.The script is given below.
CREATE TABLE #EmpDetails(EMPID int,EMPNAME NVARCHAR(10),EMPSAL int)INSERT INTO #EmpDetails VALUES (1,'RAJ',2000)INSERT INTO #EmpDetails VALUES(2,'SURESH',12000)INSERT INTO #EmpDetails VALUES(3,'SURAJ',15000)INSERT INTO #EmpDetails VALUES(4,'SUNEEL',14000)INSERT INTO #EmpDetails VALUES(5,'SANJEEV',13000)INSERT INTO #EmpDetails VALUES(6,'ATUL',12070)INSERT INTO #EmpDetails VALUES(7,'VINEET',12600)INSERT INTO #EmpDetails VALUES(8,'VIVEK',12700)
Now Check the table for values.
select * from #EmpDetails
It will display The following Rows.
EMPID | EMPNAME | EMPSAL |
---|---|---|
1 | RAJ | 2000 |
2 | SURESH | 12000 |
3 | SURAJ | 15000 |
4 | SUNEEL | 14000 |
5 | SANJEEV | 13000 |
6 | ATUL | 12070 |
7 | VINEET | 12600 |
8 | VIVEK | 12700 |
Once table creation is completed now we will see different ways to get 2nd, 3rd, etc or nth highest salary of employee. The below sql query can be used to get 1st, 2nd, 3rd, 4th, 5th ….etc highest salary of employee.
SELECT TOP 1 EMPSAL FROM ( SELECT DISTINCT TOP n EMPSAL FROM #EmpDetails ORDER BY EMPSAL DESC) a ORDER BY EMPSAL
Replace n with 2 to find the second (2nd) highest salary of employee query will look like this .
SELECT TOP 1 EMPSAL FROM ( SELECT DISTINCT TOP 2 EMPSAL FROM #EmpDetails ORDER BY EMPSAL DESC) a ORDER BY EMPSAL
Result will be
EMPSAL
----------
14000
Replace n with 3 to find the third (3rd) highest salary of employee query will look like this .
SELECT TOP 1 EMPSAL FROM ( SELECT DISTINCT TOP 3 EMPSAL FROM #EmpDetails ORDER BY EMPSAL DESC) a ORDER BY EMPSAL
Result will be
EMPSAL
-------------
13000
This topic is about sql server Comma Separated Values(csv) from Table Column.
There are Many times where we need to convert a set of rows in a single column to a comma separated (CSV) string , in this article i am going to tell you how you can get csv values from sql server table column.
For this sql server query example i have created a Temporary Table in Sql Server Database.
CREATE TABLE #MyTable(Column1 NVARCHAR(10))
INSERT INTO #MyTable VALUES('sdf')INSERT INTO #MyTable VALUES('dfg')INSERT INTO #MyTable VALUES('ghj')INSERT INTO #MyTable VALUES('rty')INSERT INTO #MyTable VALUES('hjk')
Here i am showing Two methods to create Comma Separated Values(csv) from Table Column.
1-Create Comma Seperated Values(CSV) Using COALESCE Method
DECLARE @MakeStr VARCHAR(200)
SELECT @MakeStr = COALESCE(@MakeStr+',' ,'') + Column1
FROM #MyTable
SELECT @MakeStr as MyCSV
2-Create Comma Seperated String Using XML Method
DECLARE @MakeStr VARCHAR(200)
SELECT SUBSTRING(
(SELECT ',' + Column1
FROM #MyTable
ORDER BY Column1
FOR XML PATH('')),2,200) AS MyCSV
And the result for the above Sql Query Will be
MyCSV
——————–
sdf,dfg,ghj,rty,hjk
MyCSV
——————–
dfg,ghj,hjk,rty,sdf
And the result for the above Sql Query Will be
MyCSV
——————–
sdf,dfg,ghj,rty,hjk
MyCSV
——————–
dfg,ghj,hjk,rty,sdf
Here is the sql query that will return recently executed T-SQL query on database.
SELECT QS.last_execution_time AS
[Time], dest.TEXT AS [Query]
FROM sys.dm_exec_query_stats AS
QS
CROSS APPLY sys.dm_exec_sql_text(QS.sql_handle) AS dest
ORDER BY
QS.last_execution_time DESC
Error Message:
.Net SqlClient Data Provider: Msg 10054, Level 20, State 0, Line 0
A transport-level error has occurred when sending the request to the server. (provider: TCP Provider, error: 0 – An existing connection was forcibly closed by the remote host.)
This error Occurs when the connection is forcibly closed by SQL Server.
Possible Reasons:
- When the connection was IDLE for a long time
- SQL Server Service is restarted / Stopped
- The database to which the connection is connected to is restored
- KILL Command is issued by any other user.
Solution/fix:
The best solution to this problem is Try to reconnect to the server.
.Net SqlClient Data Provider: Msg 10054, Level 20, State 0, Line 0
A transport-level error has occurred when sending the request to the server. (provider: TCP Provider, error: 0 – An existing connection was forcibly closed by the remote host.)
This error Occurs when the connection is forcibly closed by SQL Server.
Possible Reasons:
- When the connection was IDLE for a long time
- SQL Server Service is restarted / Stopped
- The database to which the connection is connected to is restored
- KILL Command is issued by any other user.
Solution/fix:
The best solution to this problem is Try to reconnect to the server.
Here is a SQL Query to find the list of Functions in SQL Server database.When you run this query it will show the list of all functions in SQL Server DataBase.
SELECT name FROM sys.objects
WHERE type
IN ('AF ','FN', 'IF', 'TF', 'FS', 'FT')