Posts

Showing posts from July, 2016

Delete duplicate records from table in SQL Server using ROW_NUMBER()

Image
In this  article I will explain how to   Delete duplicate records from table in SQL Server using ROW_NUMBER(). sometimes we required to delete duplicate records from a table  . Suppose we have a table  with some duplicate data  GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[tbl_Students]( [Id] [int] IDENTITY(1,1) NOT NULL, [Name] [nvarchar](50) NULL, [Class] [nchar](10) NULL,  CONSTRAINT [PK_tbl_Students] PRIMARY KEY CLUSTERED  ( [Id] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO Now Create Query for delete and Excute it  WITH Tempstudents(Name,duplicateCount) AS ( SELECT Name,ROW_NUMBER() OVER(PARTITION by Name ORDER BY Name)  AS duplicateCount FROM tbl_Students ) DELETE FROM Tempstudents WHERE duplicateCount > 1  Snapshot After Excut...

how to check duplicate record before insert in asp.net

Image
In this  article I will explain how to  check duplicate record before insert in asp.net  using Stored Procedure  Step1 - Create table and Stored Procedure  GO /****** Object:  Table [dbo].[tbl_Login]    Script Date: 7/5/2016 10:56:06 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[tbl_Login]( [Id] [int] IDENTITY(1,1) NOT NULL, [UserName] [nvarchar](50) NULL, [Password] [nvarchar](50) NULL,  CONSTRAINT [PK_tbl_Login] PRIMARY KEY CLUSTERED  ( [Id] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO insert into tbl_Login (Username,Password)values('admin',123456) select * from tbl_Login CREATE PROCEDURE Insertintologin     @Username varchar(100),     @Password varchar(100)   AS BEGIN     SET NOCOUNT ON;     IF EXISTS(SEL...

Transfer data from one page to another page in asp.net from different ways

In this short article I will explain how to  Transfer data from one page to another page in asp.net from different ways. 1. Use Cookies: protected void CookiesButton_Click(object sender, EventArgs e)         {             HttpCookie cook =  new HttpCookie("id");             cook.Expires = DateTime.Now.AddDays(1);             cook.Value = txtid.Text;              Response.Cookies.Add(cook);              Response.Redirect("Demopage.aspx");         } //On  Demopage: protected void Page_Load(object sender, EventArgs e)         {             labelid.Text = Request.Cookies["id"].Value;         } 2. Use the querystring : protected void RedirectButton_Click(object sender, EventArgs e)  ...