Posts

Encryption or Decryption using TripleDES

private string TripleDESEncrypt(string tbMessage)         {             try             {                 TripleDES threedes = new TripleDESCryptoServiceProvider();                 threedes.Key = StringToByte(tbKey, 24); // convert to 24 characters - 192 bits                 threedes.IV = StringToByte("12345678");                 byte[] key = threedes.Key;                 byte[] IV = threedes.IV;                 ICryptoTransform encryptor = threedes.CreateEncryptor(key, IV);                 MemoryStream msEncrypt = new MemoryStream();                 CryptoStream csEncrypt = new...

How to fill year in Dropdown List

public void FillYearCombo(DropDownList ddl, int CurrYear, int PrevYear, int extraField)         {             try             {                 ListItem ddlItem;                 ddl.Items.Clear();                 int YearDiff;                 int[] YearList;                 int Len = 0;                 YearDiff = CurrYear - PrevYear;                 int FinalYear = PrevYear + YearDiff;                 if (extraField == 1)                 {                     YearList = new int[YearDiff +...

Show Javascript messgae and when click ok then redirect to another page

 public static void ShowMsgWithRedirect(System.Web.UI.Page objPage, string msg, string pagename)     {         ScriptManager.RegisterStartupScript(objPage, objPage.GetType(), "", "alert('" + msg + "');window.location ='" + pagename + "';", true);     }     public static void ShowMessage(System.Web.UI.Page objPage, string msg)     {         ScriptManager.RegisterStartupScript(objPage, objPage.GetType(), "", "alert('" + msg + "');", true);     }     public static void ShowConMessage(System.Web.UI.Page objPage, string msg)     {         ScriptManager.RegisterStartupScript(objPage, objPage.GetType(), "", "Confirm('" + msg + "');", true);     }

How to fill combo box with view

public static void FillComboWithView(DropDownList ddl,  DataSet ds, string displayField, string valueField,string status)     {         DataView dvMember = ds.Tables[0].DefaultView;         dvMember.RowFilter = status;         dvMember.Sort = displayField;         ddl.DataSource = dvMember;         ddl.DataTextField = displayField;         ddl.DataValueField = valueField;         ddl.DataBind();             }  

How to send email in .net

 public static void SendEmail(string fromEmail, string toEmail, string subject, string message)     {         try         {             MailMessage mailMessage = new MailMessage(fromEmail, toEmail);             mailMessage.Subject = subject;             mailMessage.Body = message;             mailMessage.IsBodyHtml = true;             SmtpClient client = new SmtpClient();             client.Host = "smtp.gmail.com" ;             client.EnableSsl = true;             client.Credentials = new System.Net.NetworkCredential("test@gmail.com", "password");             client.Send(mailMessage);         }         catch (Ex...

What is difference between function and stored procedure

Functions  ----------  1) can be used with Select statement  2) Not returning output parameter but returns Table variables  3) You can join UDF  4) Cannot be used to change server configuration  5) Cannot be used with XML FOR clause  6) Cannot have transaction within function  Stored Procedure  -----------------  1) have to use EXEC or EXECUTE  2) return output parameter  3) can create table but won't return Table Variables  4) you can not join SP  5) can be used to change server configuration  6) can be used with XML FOR Clause  7) can have transaction within SP

Create Function For Generate Code of Database

ALTER FUNCTION [dbo].[GetMemberRegNo] (  @AccountID INT ) RETURNS VARCHAR(20) AS BEGIN     DECLARE @CodeLengthInTable AS INT       DECLARE @LastCodeInTable AS VARCHAR(20)     DECLARE @LastCodeValue AS INT     DECLARE @LatestCode AS VARCHAR(20)     DECLARE @VARCODE AS VARCHAR(2)     SET @VARCODE='DS'     DECLARE @TOTALPatient AS BIGINT     SELECT @TOTALPatient=COUNT(PatientID) FROM dbo.Patient WITH(NOLOCK) WHERE Patient_AccountID=@AccountID           BEGIN             SET @LastCodeValue= (ISNULL(@TOTALPatient,0) +1 )             IF LEN(@LastCodeValue)=1                 SET @LatestCode=@VARCODE + '0000' + CONVERT(VARCHAR,@LastCodeValue)             ELSE IF LEN(@LastCodeValue)=2             ...