Posts

Showing posts from 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)  ...

Export div content to PDF Using ITextSharp in asp.net

Image
In this short article I will explain how to export content in a div to a PDF using ITextSharp  in ASP.Net. Step1: ITextSharp is a free and open source assembly that helps to convert page output or HTML content in a PDF file.Download it first from given link  and add dll file in bin folder- https://sourceforge.net/projects/itextsharp/files/itextsharp/ Step2 -add Page <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Studentdetails.aspx.cs" Inherits="Studentdetails" EnableEventValidation = "false" %> <!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">     <title></title> </head> <body>     <form id="form1" runat="server">   <div id="studentdetails" runat=...

Bootstrap Modal Popup keep open on PostBack in ASP.Net

In This tutorial will show you how keep open Bootstrap Modal Popup when Postback in asp.net I have added one button inside  bootstrap model. in some requirement we need to save data and get some output on popup after button click in model popup . source code- <form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <div class="container"> <div class="row"> <h1> Hello, world! Hello, world!</h1> <!-- jQuery (necessary for Bootstrap's JavaScript plugins) --> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script> <!-- Include all compiled plugins (below), or include individual files as needed --> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min....

How to Send Email with Attachment using ASP.NET with c#

This tutorial will show you how to send a simple email message with an attachment using ASP.NET with C# Sending a email with an attachment using ASP.NET is actually very simple.First, you will need to import the System.Net.Mail namespace.The System.Net.Mail namespace contains the SmtpClient and MailMessage Classes that we need in order to send the email and the message attachment. aspx page <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server">     <title></title> </head> <body>     <form id="form1" runat="server">     <div>     <table  >     <tr>         <td style="width: 80px">             To:         </td>         ...