Friday, May 10, 2013

Delete duplicate record from Table SQL

Create Table :


CREATE Table [Order]
(
ID INT Primary key NOT NULL IDENTITY(1,1),
NAME NVARCHAR(MAX),
Quantity INT,
Price INT
)

Insert duplicate record into the table:


INSERT INTO [ORDER](NAME,Quantity,Price) VALUES('SIBASIS',1,10)
INSERT INTO [ORDER](NAME,Quantity,Price) VALUES('SIBASIS',1,1)
INSERT INTO [ORDER](NAME,Quantity,Price) VALUES('SIBASIS',1,2)
INSERT INTO [ORDER](NAME,Quantity,Price) VALUES('SIBASIS',1,3)
INSERT INTO [ORDER](NAME,Quantity,Price) VALUES('SIBASIS',1,11)

INSERT INTO [ORDER](NAME,Quantity,Price) VALUES('Manua',1,10)
INSERT INTO [ORDER](NAME,Quantity,Price) VALUES('Manua',1,10)
INSERT INTO [ORDER](NAME,Quantity,Price) VALUES('Manua',1,10)

INSERT INTO [ORDER](NAME,Quantity,Price) VALUES('Kalia',1,1)
INSERT INTO [ORDER](NAME,Quantity,Price) VALUES('Kalia',1,1)
INSERT INTO [ORDER](NAME,Quantity,Price) VALUES('Tiki',1,1)
INSERT INTO [ORDER](NAME,Quantity,Price) VALUES('Tiki',1,1)

Delete Duplicate record:

DELETE FROM [Order] WHERE ID NOT IN (SELECT MAX(ID) FROM [Order] GROUP BY NAME)


Call Javascript function from codebehind page (Asp.Net)

If you want to alert some thing then this will be very useful to you.:

Page.ClientScript.RegisterStartupScript(this.GetType(), "Call my function", "javascript:alert('sss');", true); 

If you want to call a javascript function  then this will be very useful to you.:

In code behind page:(aspx.cs)
Page.ClientScript.RegisterStartupScript(this.GetType(), "Call my function", "myJavaScriptFunction()", true); 

In (aspx):
<script type="text/javascript">
    function myJavaScriptFunction() 
                  {
                            //Do your javascript here
                  }
</script>

Tuesday, December 25, 2012

Send mail code in classic ASP



'To send mail

Sub sendEmail(mailFrom, mailTo, mailSubject, mailMessage, mailServer, mailUsername, mailPassword)
Set TestMail = CreateObject("cdo.message")
TestMail.From = mailFromAddress
TestMail.To = mailToAddress
TestMail.Subject = mailSubject
TestMail.HTMLBody = mailMessage
TestMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
TestMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = mailServerIP
TestMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = mailUsername
TestMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = mailPassword
TestMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
TestMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
TestMail.Configuration.Fields.Update
TestMail.Send
Set TestMail = nothing
End Sub


'To save mail in your local pickup directory.

Sub sendEmail(mailFrom, mailTo, mailSubject, mailMessage, mailServer, mailUsername, mailPassword)
Set TestMail = CreateObject("cdo.message")
TestMail.From = mailFromAddress
TestMail.To = mailToAddress
TestMail.Subject = mailSubject
TestMail.HTMLBody = mailMessage
TestMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 1
TestMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = mailServerIP
TestMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverpickupdirectory") = "C:\temp\maildrop"
TestMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = mailUsername
TestMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = mailPassword
TestMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
TestMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
TestMail.Configuration.Fields.Update
TestMail.Send
Set TestMail = nothing
End Sub

Thursday, October 25, 2012

C# Memory Leak Dispose

A memory leak occurs when we consume memory and forget to release it.

Ex:   Suppose we initialize an object and forget to dispose.

We should dispose object , if the object is IDisposable .

Monday, August 27, 2012

Convert Date to string in ASP.NET

string date = DateTime.Today.Date.ToString("dd/MM/yyyy"); //Result "27/08/2012"
string date = DateTime.Today.Date.ToString("dd_MM_yyyy"); //Result "27_08_2012"
string date =DateTime.Today.Date.ToString("MMMM"); //Result "August"
string date =DateTime.Today.Date.ToString("MMM"); //Result "Aug"

Thursday, November 17, 2011

Session


session is a variable used to transmit information from one page to another page.
session is used to persist the current user.
Http is a stateless protocol this means that web server treats each request as an independent request
The server retains no knowledge  of variable values that were used in previous request.