Sunday, February 8, 2015

Add a column, with a default value, to an existing table in SQL Server



Syntax


 ALTER TABLE {TABLENAME}   
 ADD {COLUMNNAME} {TYPE} {NULL|NOT NULL}   
 CONSTRAINT {CONSTRAINT_NAME} DEFAULT {DEFAULT_VALUE}  
 [WITH VALUES]  

Example


 ALTER TABLE table  
 ADD column BIT   
 CONSTRAINT Constraint_name DEFAULT 0 WITH VALUES  


Note : WITH VALUES handles the NOT NULL part...

Monday, January 12, 2015

Convert 12 Hour format to 24 Hour Format asp.net C#


12 to 24

   private string ConvertTo24HourFormat(string strTime)  //HH:MM AM/PM
   {  
     string FinalTime=string.Empty;  
     if (!string.IsNullOrEmpty(strTime))  
     {  
       try  
       {  
         string[] InTime = strTime.Split(':');  
         int h = Convert.ToInt32(InTime[0].ToString());  
         string[] AMPM = InTime[1].Split(' ');  
         if (AMPM[1].ToString() == "PM")  
         {  
           h += 12;  
         }  
         if (AMPM[1].ToString() == "AM" && h.ToString()=="12")  
         {  
           h = 00;  
         }  
         FinalTime = h + ":" + InTime[1];  
         //if(h>  
       }  
       catch (Exception) { }  
     }  
     return FinalTime;  
   }  

24 to 12

  private string ConvertTo12HourFormat(string strTime)  //HH:MM AM/PM
   {  
     string FinalTime = string.Empty;  
     if (!string.IsNullOrEmpty(strTime))  
     {  
       try  
       {  
         string[] InTime = strTime.Split(':');  
         int h = Convert.ToInt32(InTime[0].ToString());  
         string[] AMPM = InTime[1].Split(' ');  
         if (AMPM[1].ToString() == "PM")  
         {  
           h -= 12;  
         }  
         if (AMPM[1].ToString() == "AM" && h.ToString() == "00")  
         {  
           h = 12;  
         }  
         FinalTime = h + ":" + InTime[1];  
         //if(h>  
       }  
       catch (Exception) { }  
     }  
     return FinalTime;  
   }  

Monday, January 5, 2015

Fire event on enter key press for a textbox

ASPX:

 <asp:TextBox ID="TextBox1" clientidmode="Static" runat="server" onkeypress="return EnterEvent(event)"></asp:TextBox>    
 <asp:Button ID="Button1" runat="server" style="display:none" Text="Button" />  

JS:
 
 function EnterEvent(e) {  
     if (e.keyCode == 13) {  
       __doPostBack('<%=Button1.UniqueId%>', "");  
     }  
   }  


CS:

 protected void Button1_Click1(object sender, EventArgs e)  
   {  
   }  

Thursday, December 18, 2014

Stock Price Plugin Live


Source
 <iframe frameborder="0" src="http://www.indianotes.com/widgets/indices-ticker/index.php?type=indices-ticker&w=500" width="500" height="100" scrolling="no"></iframe>  
Demo