, , , ,

Play Video with asp.net and c#

.flv is the preferred format to play videos online. You can download .flv player from http://www.any-flv-player.com and then go to Publish>>Publish for web.

This will generate code copy and paste code to .aspx page. It will start playing your .flv file

You can face a major problem on server or IIS it will not play video. Go to settings and set MIME type to .flv
Share:
Read More
, , ,

How to make user in Sql server database.

To make a user in sql server you have the rights. to create user go to Security=>>

Logins>> Right click on Logins

Login Name : jayant

Select option:Sql server authentication

Un check : Enforece password policy. Refer Image Below





Now close sql management studio and re login with jayant

Try to access other databases, it will show error, means you have sucessfuly make a new use for new datbase.

Share:
Read More
, ,

Crosstab report in SQL server (Pivot)

Microsoft introduces new operators PIVOT and UNPIVOT in SQL Server 2005. Traditionally we create queries using the CASE statement and aggregate function in order to produce cross-tab reports. This article illustrates the usage of the new operators, PIVOT and UNPIVOT.
Let us assume that we have a table as described below.
Create table #MyTable
(yearofJoining int,
EmpId int,
Deptid int)
go
insert into #MyTable select 1990,1,1
insert into #MyTable select 1991,2,2
insert into #MyTable select 1990,3,4
insert into #MyTable select 1991,4,2
insert into #MyTable select 1990,5,1
insert into #MyTable select 1990,6,3
insert into #MyTable select 1992,7,3
insert into #MyTable select 1990,8,4
insert into #MyTable select 1993,9,1
insert into #MyTable select 1994,10,2
insert into #MyTable select 1990,11,3
insert into #MyTable select 1995,12,3
insert into #MyTable select 1995,14,3
insert into #MyTable select 1995,15,3
insert into #MyTable select 1995,16,6
go

In order to create a cross tab report, we used to execute the query as described below.
--Original Cross Tab query
select YearofJoining,
count(case [DeptId] when 1 then 1 else null end) as [Department-1],
count(case [DeptId] when 2 then 1 else null end) as [Department-2],
count(case [DeptId] when 3 then 1 else null end) as [Department-3]
from #MyTable where deptid in(1,2,3)
group by Yearofjoining
This would produce the result as shown below.
YearofJoining Department-1 Department-2 Department-3
------------- ------------ ------------ ------------
1990Microsoft introduces new operators PIVOT and UNPIVOT in SQL Server 2005. Traditionally we create queries using the CASE statement and aggregate function in order to produce cross-tab reports. This article illustrates the usage of the new operators, PIVOT and UNPIVOT.
Let us assume that we have a table as described below.
Create table #MyTable
(yearofJoining int,
EmpId int,
Deptid int)
go
insert into #MyTable select 1990,1,1
insert into #MyTable select 1991,2,2
insert into #MyTable select 1990,3,4
insert into #MyTable select 1991,4,2
insert into #MyTable select 1990,5,1
insert into #MyTable select 1990,6,3
insert into #MyTable select 1992,7,3
insert into #MyTable select 1990,8,4
insert into #MyTable select 1993,9,1
insert into #MyTable select 1994,10,2
insert into #MyTable select 1990,11,3
insert into #MyTable select 1995,12,3
insert into #MyTable select 1995,14,3
insert into #MyTable select 1995,15,3
insert into #MyTable select 1995,16,6
go

In order to create a cross tab report, we used to execute the query as described below.
--Original Cross Tab query
select YearofJoining,
count(case [DeptId] when 1 then 1 else null end) as [Department-1],
count(case [DeptId] when 2 then 1 else null end) as [Department-2],
count(case [DeptId] when 3 then 1 else null end) as [Department-3]
from #MyTable where deptid in(1,2,3)
group by Yearofjoining
This would produce the result as shown below.
YearofJoining Department-1 Department-2 Department-3
------------- ------------ ------------ ------------
1990      2 0 2
1991 0 2 0
1992 0 0 1
1993 1 0 0
1994 0 1 0
1995 0 0 3


The same results can be reproduced using the operator, PIVOT.
--New PIVOT Operator in SQL 2005
SELECT YearofJoining, [1] as [Department-1],[2] as [Department-2],
[3] as [Department-3] FROM
(SELECT YearOfJoining,Deptid from #MyTable) p
PIVOT
( Count(DeptId) for DEPTID in ([1],[2],[3]))
AS pvt
ORDER BY Yearofjoining
Now let us assume the we have have a table as decribed below.
create table #MyTable2 (BatchID int ,Status int)
go
insert into #MyTable2 select 1001 ,1
insert into #MyTable2 select 1001 ,2
insert into #MyTable2 select 1002 ,0
insert into #MyTable2 select 1002 ,3
insert into #MyTable2 select 1002 ,4
insert into #MyTable2 select 1003 ,4
insert into #MyTable2 select 1004 ,4
go


In order to create a cross tab report, we used to execute the query as described below.
--Original Cross Tab query
select batchid,
sum(case status when 0 then 1 else 0 end) as [status-0],
sum(case status when 1 then 1 else 0 end) as [status-1],
sum(case status when 2 then 1 else 0 end) as [status-2],
sum(case status when 3 then 1 else 0 end) as [status-3],
sum(case status when 4 then 1 else 0 end) as [status-4]
from #MyTable2
group by batchid
This would produce the result as shown below.
BatchId Status-0 Status-1 Status-2 Status-3 Status-4
----------- ----------- ----------- ----------- ----------- -----------
1001 0 1 1 0 0
1002 1 0 0 1 1
1003 0 0 0 0 1
1004 0 0 0 0 1



--New PIVOT Operator in SQL 2005
SELECT BatchId, [0]as [Status-0],
[1]as [Status-1],
[2] as [Status-2],
[3]as [Status-3],
[4]as [Status-4]
FROM
(SELECT BatchId,status from #MyTable2) p
PIVOT
( count(Status) for status in ([0],[1],[2],[3],[4]))
AS pvt
ORDER BY BatchId
Notice, in the traditional cross tab query I am using the aggregate function sum and in the new PIVOT query I am using count.
Let us try using the aggregate function sum in the new PIVOT query.
--New PIVOT Operator in SQL 2005
SELECT BatchId, [0]as [Status-0],
[1]as [Status-1],
[2] as [Status-2],
[3]as [Status-3],
[4]as [Status-4]
FROM
(SELECT BatchId,status from #MyTable2) p
PIVOT
(sum(Status) for status in ([0],[1],[2],[3],[4]))
AS pvt
ORDER BY BatchId
You would get the result as described below.
BatchId Status-0 Status-1 Status-2 Status-3 Status-4
----------- ----------- ----------- ----------- ----------- -----------
1001 NULL 1 2 NULL NULL
1002 0 NULL NULL 3 4
1003 NULL NULL NULL NULL 4
1004 NULL NULL NULL NULL 4

As you see, when we use the new operator PIVOT with the same aggregate function we will not get the desired results. Instead of getting the Yes/No status we get the actual status value.
Let's assume we have a table that looks like the cross tab report described below.
create table #mycrosstab(
BatchId int, [Status-0] int, [Status-1] int,
[Status-2] int, [Status-3] int, [Status-4] int)
go
insert into #mycrosstab select 1001,0,1, 1, 0, 0
insert into #mycrosstab select 1002,1,0, 0, 1, 1
insert into #mycrosstab select 1003,0,0, 0, 0, 1
insert into #mycrosstab select 1004,0,0, 0, 0, 1
go
Let's try to reverse the crosstab report in order to get the original table using the new operator UNPIVOT.
SELECT BatchId, Status,StatusValue
FROM
(SELECT BatchId , [Status-0] , [Status-1] , [Status-2] , [Status-3], [Status-4]
FROM #mycrosstab ) p
UNPIVOT
(StatusValue FOR status IN
( [Status-0] , [Status-1] , [Status-2] , [Status-3], [Status-4])
)AS unpvt

BatchId Status StatusValue
1001 Status-0 0
1001 Status-1 1
1001 Status-2 1
1001 Status-3 0
1001 Status-4 0
1002 Status-0 1
1002 Status-1 0
1002 Status-2 0
1002 Status-3 1
1002 Status-4 1
1003 Status-0 0
1003 Status-1 0
1003 Status-2 0
1003 Status-3 0
1003 Status-4 1
1004 Status-0 0
1004 Status-1 0
1004 Status-2 0
1004 Status-3 0
1004 Status-4 1
Using the case statement and UNPIVOT operator, you can bring back the original table as described below
SELECT BatchId, MyStatus= case
when status= 'Status-0' and statusvalue =1 then '0'
when status= 'Status-1' and statusvalue =1 then '1'
when status= 'Status-2' and statusvalue =1 then '2'
when status= 'Status-3' and statusvalue =1 then '3'
when status= 'Status-4' and statusvalue =1 then '4' end
,StatusValue
FROM
(SELECT BatchId , [Status-0] , [Status-1] , [Status-2] , [Status-3], [Status-4]
FROM #mycrosstab ) p
UNPIVOT
(StatusValue FOR status IN
( [Status-0] , [Status-1] , [Status-2] , [Status-3], [Status-4])
)AS unpvt
BatchId MyStatus StatusValue
1001 NULL 0
1001 1 1
1001 2 1
1001 NULL 0
1001 NULL 0
1002 0 1
1002 NULL 0
1002 NULL 0
1002 3 1
1002 4 1
1003 NULL 0
1003 NULL 0
1003 NULL 0
1003 NULL 0
1003 4 1
1004 NULL 0
1004 NULL 0
1004 NULL 0
1004 NULL 0
1004 4 1

2 0 2
1991 0 2 0
1992 0 0 1
1993 1 0 0
1994 0 1 0
1995 0 0 3


The same results can be reproduced using the operator, PIVOT.
--New PIVOT Operator in SQL 2005
SELECT YearofJoining, [1] as [Department-1],[2] as [Department-2],
[3] as [Department-3] FROM
(SELECT YearOfJoining,Deptid from #MyTable) p
PIVOT
( Count(DeptId) for DEPTID in ([1],[2],[3]))
AS pvt
ORDER BY Yearofjoining
Now let us assume the we have have a table as decribed below.
create table #MyTable2 (BatchID int ,Status int)
go
insert into #MyTable2 select 1001 ,1
insert into #MyTable2 select 1001 ,2
insert into #MyTable2 select 1002 ,0
insert into #MyTable2 select 1002 ,3
insert into #MyTable2 select 1002 ,4
insert into #MyTable2 select 1003 ,4
insert into #MyTable2 select 1004 ,4
go


In order to create a cross tab report, we used to execute the query as described below.
--Original Cross Tab query
select batchid,
sum(case status when 0 then 1 else 0 end) as [status-0],
sum(case status when 1 then 1 else 0 end) as [status-1],
sum(case status when 2 then 1 else 0 end) as [status-2],
sum(case status when 3 then 1 else 0 end) as [status-3],
sum(case status when 4 then 1 else 0 end) as [status-4]
from #MyTable2
group by batchid
This would produce the result as shown below.
BatchId Status-0 Status-1 Status-2 Status-3 Status-4
----------- ----------- ----------- ----------- ----------- -----------
1001 0 1 1 0 0
1002 1 0 0 1 1
1003 0 0 0 0 1
1004 0 0 0 0 1



--New PIVOT Operator in SQL 2005
SELECT BatchId, [0]as [Status-0],
[1]as [Status-1],
[2] as [Status-2],
[3]as [Status-3],
[4]as [Status-4]
FROM
(SELECT BatchId,status from #MyTable2) p
PIVOT
( count(Status) for status in ([0],[1],[2],[3],[4]))
AS pvt
ORDER BY BatchId
Notice, in the traditional cross tab query I am using the aggregate function sum and in the new PIVOT query I am using count.
Let us try using the aggregate function sum in the new PIVOT query.
--New PIVOT Operator in SQL 2005
SELECT BatchId, [0]as [Status-0],
[1]as [Status-1],
[2] as [Status-2],
[3]as [Status-3],
[4]as [Status-4]
FROM
(SELECT BatchId,status from #MyTable2) p
PIVOT
(sum(Status) for status in ([0],[1],[2],[3],[4]))
AS pvt
ORDER BY BatchId
You would get the result as described below.
BatchId Status-0 Status-1 Status-2 Status-3 Status-4
----------- ----------- ----------- ----------- ----------- -----------
1001 NULL 1 2 NULL NULL
1002 0 NULL NULL 3 4
1003 NULL NULL NULL NULL 4
1004 NULL NULL NULL NULL 4

As you see, when we use the new operator PIVOT with the same aggregate function we will not get the desired results. Instead of getting the Yes/No status we get the actual status value.
Let's assume we have a table that looks like the cross tab report described below.
create table #mycrosstab(
BatchId int, [Status-0] int, [Status-1] int,
[Status-2] int, [Status-3] int, [Status-4] int)
go
insert into #mycrosstab select 1001,0,1, 1, 0, 0
insert into #mycrosstab select 1002,1,0, 0, 1, 1
insert into #mycrosstab select 1003,0,0, 0, 0, 1
insert into #mycrosstab select 1004,0,0, 0, 0, 1
go
Let's try to reverse the crosstab report in order to get the original table using the new operator UNPIVOT.
SELECT BatchId, Status,StatusValue
FROM
(SELECT BatchId , [Status-0] , [Status-1] , [Status-2] , [Status-3], [Status-4]
FROM #mycrosstab ) p
UNPIVOT
(StatusValue FOR status IN
( [Status-0] , [Status-1] , [Status-2] , [Status-3], [Status-4])
)AS unpvt

BatchId Status StatusValue
1001 Status-0 0
1001 Status-1 1
1001 Status-2 1
1001 Status-3 0
1001 Status-4 0
1002 Status-0 1
1002 Status-1 0
1002 Status-2 0
1002 Status-3 1
1002 Status-4 1
1003 Status-0 0
1003 Status-1 0
1003 Status-2 0
1003 Status-3 0
1003 Status-4 1
1004 Status-0 0
1004 Status-1 0
1004 Status-2 0
1004 Status-3 0
1004 Status-4 1
Using the case statement and UNPIVOT operator, you can bring back the original table as described below
SELECT BatchId, MyStatus= case
when status= 'Status-0' and statusvalue =1 then '0'
when status= 'Status-1' and statusvalue =1 then '1'
when status= 'Status-2' and statusvalue =1 then '2'
when status= 'Status-3' and statusvalue =1 then '3'
when status= 'Status-4' and statusvalue =1 then '4' end
,StatusValue
FROM
(SELECT BatchId , [Status-0] , [Status-1] , [Status-2] , [Status-3], [Status-4]
FROM #mycrosstab ) p
UNPIVOT
(StatusValue FOR status IN
( [Status-0] , [Status-1] , [Status-2] , [Status-3], [Status-4])
)AS unpvt
BatchId MyStatus StatusValue
1001 NULL 0
1001 1 1
1001 2 1
1001 NULL 0
1001 NULL 0
1002 0 1
1002 NULL 0
1002 NULL 0
1002 3 1
1002 4 1
1003 NULL 0
1003 NULL 0
1003 NULL 0
1003 NULL 0
1003 4 1
1004 NULL 0
1004 NULL 0
1004 NULL 0
1004 NULL 0
1004 4 1
Share:
Read More
,

Event after Load

Yes there is an event LoadComplete()
for ex.
protected void Page_LoadComplete(object sender, EventArgs e)

This event is for tasks that require that all other controls on the page be loaded.

Suppose I have to show messages on page and then I have to redirect to some other page.

I Have a small example; I have a page which connect me to some more URL’s but to some reasons I have shift that page to another location.

Now I have to show message on page
“this page has shifted to another location. This page will automatically redirect to another page”

So, this can be done only after page load so, this is the best event to place that code
Share:
Read More
, , ,

Randomly Sort Sql server Table

You can sort a Table Randomly with a single keyword.

the newsid() is the keyword which generates a random number in sql server.

Here is small ex.

1)Create a database
2)Create Table Master
3)Create Fields Code nvarchar(50), Name Nvarchar(50)
4)Enter some data into table
5)Now open new query window
6)Write sql
7)Select * from Master Order by newid()

Now, run this code it will return data in random format.

You can also use newid() to generate a unique number or a number like verification code etc.

for ex.

Select newid()
Share:
Read More
, ,

Sort Datatable randomly

This is not possible to Sort a Datatable directly.

In order to randomize the rows in a DataTable, do the following:

1) Add a random number DataColumn to the DataTable

2) For each row, generate a random number and store it to the new column

3) Create a DataView and sort by the random number DataColumn

Test this by simple ex.

DataTable dt = GetData();
dt.Columns.Add(new DataColumn("RandomNum", Type.GetType("System.Int32")));

Random random = new Random();
for (int i = 0; i < dt.Rows.Count; i++)
{
dt.Rows[i]["RandNum"] = random.Next(1000);
}

DataView dv = new DataView(dt);
dv.Sort = "RandomNum";
Share:
Read More
, , , ,

How to use Hindi fonts on Website

Now in current world the importance of multi lingual websites has increased.
People demands for sites in different languages for different uses.

I have a site on which I have to show data in Hindi.
This had become a major issue while development.

I had searched the internet and found a solution named Microsoft WEFT.
I was very happy to find a solution. I start working on the basis of
this software. But after successful launch of website the use had found
an major issue. The .eot files are only supported on IE browsers.

Now, this is the time to work like a machine to search for a true solution.

I have searched many sites.

But, finally god give me the solution by giving me the concept of UNICODE fonts

Here is the example how to use UNICODE fonts.

use these sites to make entry in hindi

http://utopianvision.co.uk/hindi/write/
http://www.geocities.com/matthewblackwell/hindiEditor.html

You can make entry in hindi for ex.
on this http://utopianvision.co.uk/hindi/write/

in second text box enter
aam

bharat

mahaaraaNaa

these will get appear in the second box.

copy text and paste where ever you want. Unicode fonts are browser compatible.

If you want to insert UNICODE fonts into database, you have to take a UNICODE supported field i.e.
Nvarchar datatype don't use varchar datatype.


Please let me know if you want to know more about this.
Share:
Read More
, ,

aspnet_merge.exe exited with code '1'

This is a major problem which will normally faced by new users of .net.

The main reason behind the problem is the duplicate "Inherits" name of pages.

You can easily resolve this problem by renaming the duplicate inherit names of Pages.

Let me describe this by giving an simple ex.

steps :-
1) Make a new c# website.
2) By default an page default.aspx will appear.
3 Copy default.aspx and paste
4) Rename copy of default to "Default2.aspx"
5) Then try to make build.
6) It will show errors

Here, is the solution

1) Open default.aspx
2) Check Inherits attribute of page in page directive. it is "_Default" by default
3) Open default2
4) Check Inherits attribute of default2 in page directive. it is "_Default"
5) Change Inherits attribute of default2 to "_Default2"
6) Build application

Now build successfully.

This is the solution which I have explained with the help of small ex.

For any help please mail on narendersinghkahlon@gmail.com
Share:
Read More

How to change Mouse Pointer onmouseover using Javascript

JavaScript is a strong tool to work with Web Technology. You can complete all the tasks using JavaScript.

For ex. I have a task to chnage mouse pointer on mouse hover. The answer is too simple
use CSS.No, my css is not working due to some un avoidable reasons.

Finally I come to the conclusion i.e

Make a global.js contains

function set_mouse_pointer(obj)
{
obj.style.cursor='pointer';
}

Then implement this function like

Steps:
1) Put an HTML button of the page
2) Then on onmouseover event write code "onmouseover="set_mouse_pointer(this);"
3) View that page in browser.

You will see the effect.

This is a simple example of JavaScript. What you can do with JavaScript.

Please let me know if you have any major issues related to JavaScript
Share:
Read More

Set Left,Top at different screen resolution by JavaScript

I have a task to dispaly a div starts from the left position of some other control.

I had searched on so many sites but, unfortunately I have not found any good solution.

But, finally I found a solution, as I know the default left on 1024 x 768 is "251" so I use this as a gift of god.

Following is the code how to do that:-

var obj=document.getElementById("a1");
var int_left=screen.width; // get Pixel size of screen
if (int_left>1024)
{
int_left=int_left-1024; // get width other then 1024
int_left=int_left/2; get the first half of width
int_left=int_left+251; add first half to the width
}
else
{
int_left=253;
}

obj.style.left=int_left;

If you have any doubts please let me know.
Share:
Read More
, ,

SQL Server Stored Procedure paging with .net

We face Paging problem while working with datalist.

Datalist does not support paging like grid.

Here, is the solution for this major problem.

use Sql server stored procedure to get proper paging which we can call from Dot Net

Suppose I have a Table master Contains Fields "UserName,Code, Address1,FatherName" etc.

To Make this ex. working follow steps
1) Make New Database
2) Create Table Master
3) Create Fields
UserName Nvarchar(50),
Code Nvarchar(50),
Address1 Nvarchar(50),
FatherName Nvarchar(50)
4) Then run following command is sql query window.
5) After creating this exec [Get_Records] 1,10
6) First param stands for pageno and second is for No. of records per page.

-- =============================================
Create PROCEDURE [dbo].[Get_Records]
@Int_PageNo int,@Int_RecordPerPage int
AS
BEGIN
Declare @Int_From_Page int,@int_To_Page int,@Int_Total_Records int
/***********************************************/
set @Int_From_Page=((@Int_PageNo-1)*@Int_RecordPerPage)+1
set @int_To_Page=@Int_PageNo*@Int_RecordPerPage
print @Int_From_Page
print @int_To_Page
/***********************************************/
SET NOCOUNT ON;

Select @Int_Total_Records=Count(*) From Master;

WITH ListEntries AS (
SELECT ROW_NUMBER() OVER (ORDER BY Code ASC)AS Row, UserName,Code, Address1,FatherName
FROM Master
/*******************************************************************/
SELECT Row, UserName,Code, Address1,FatherName FROM ListEntries
WHERE Row between @Int_From_Page and @int_To_Page

END
Share:
Read More
,

Absolute path to Javascript

Many time we face a problem of JavaScript path

Like you have given path in Master page like "../a.js" so, if you have page at "../../../default.aspx" position it will not import this Js into your page or you will face problem with JS.

So if you want to use a perfect path for your JS use Resolve URL method.

For ex. <script type="text/javascript" src="<%=ResolveUrl("~/js/example.js")%>"></script>

This is the right way work with Dot Net and JS
Share:
Read More