Thursday, 23 May 2013

Write an SQL Query to check whether date passed to Query is date of given format or not?


SQL has IsDate() function which is used to check passed value is date or not of specified format ,it returns 1(true) or 0(false) accordingly.

SELECT  ISDATE('1/08/13') AS "MM/DD/YY";

Tuesday, 21 May 2013

Standard Date Time Format - C#


   DateTime dtDate;
   string strDate;
   strDate = string.Format("{0:d}", Convert.ToDateTime(dr["dtDate"]));
   dtDate = Convert.ToDateTime(strDate);
   strDate = dtDate.ToString("MM/dd/yyyy", new CultureInfo("en-US"));

Monday, 20 May 2013

RequiredFieldValidator and OnClientClick Together


function showContent()
{
    // if you need one group use    
    // Page_ClientValidate('VGFillHours');
    if (Page_ClientValidate())  //validates all groups
    {
        document.getElementById("<%=ImgAjaxloaderClarification.ClientID %>").style.display = "block";
    return true;
    }
return false;
}

Wednesday, 15 May 2013

How to remove diacritics (accents) from words in SQL Server


Select 'à éêöhello!' Collate SQL_Latin1_General_CP1253_CI_AI

Create Function [String].[RemoveDiacritics] ( @p_String Varchar(Max) )
Returns Varchar(Max) As
Begin
  Return @p_String Collate SQL_Latin1_General_CP1253_CI_AI;
End

Tuesday, 14 May 2013

validation expression for gmail,yahoo


<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="txtEmail"Display="Dynamic" ErrorMessage="Invalid Email" ValidationExpression="^([a-zA-Z0-9]+[a-zA-Z0-9._%-]*@(yahoo\.com|gmail\.com))"                                            ValidationGroup="reg"></asp:RegularExpressionValidator>

Thursday, 18 April 2013

How can setup a friendly email name in the MailSetting section of web.config?


Well, in code you need to put the sender's name in quotes, followed by the e-mail address.

new SmtpClient(...).Send("\"John Smith\" jsmith@somewhere.com", ...);
And...it looks like you can encode it into the attribute too...

<smtp from="&quot;John Smith&quot; &lt;jsmith@somewhere.com&gt;">

CompareValidator for “dd/mm/yyyy” format

By default the ASP.Net CompareValidator does not work for dd/mm/yyyy format hence we will need to change the Culture property of the page to en-GB in the @Pagedirective of the ASP.Net Web Page as show below

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Request.aspx.cs" Inherits="Request" Culture = "en-GB"  %>