Monday, March 6, 2017

Looping in SQL Server

DECLARE @cnt INT = 1;
WHILE @cnt < (select max(id) FROM [Item])
BEGIN  
 
  update [Stock]
  set [PurchaseQty] = (select [SaleQty] + [BalanceQty] FROM [Stock] where ItemId = @cnt)
  where ItemId = @cnt  
 
  SET @cnt = @cnt + 1;

END;

Saturday, January 14, 2017

Timer in Web Form

Process-1 (Using C# in ASP.Net Page):

<asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>

            <asp:Timer ID="Timer1" runat="server" Interval="100" ontick="Timer1_Tick"> </asp:Timer>
            <asp:UpdatePanel ID="UpdatePanel1" runat="server">

                <ContentTemplate>

              <table style="height:30px; width: 100%; font-size: small;">
                <tr>
                    <td bgcolor="#40541C"
                        style= "color: #FFFFFF; text-align: right; width: 250px;">
                        <asp:Label ID="lblTimer" runat="server"></asp:Label>
                    </td>
                   
                </tr>
            </table>

                    </ContentTemplate>

                <Triggers>

                <asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick"></asp:AsyncPostBackTrigger>

            </Triggers>

         </asp:UpdatePanel>



protected void Timer1_Tick(object sender, EventArgs e)
        {
            lblTimer.Text = "Date Time: " + DateTime.Now.ToString("dd.MM.yyyy,  hh:mm:ss  tt");
        }





Process-2 (Using JavaScript):

<script type="text/javascript">
        function ShowCurrentTime() {
            var dt = new Date();
            //var date =
            document.getElementById("lblTime").innerHTML = dt.toDateString() + ', ' + dt.toLocaleTimeString();
            window.setTimeout("ShowCurrentTime()", 1000); // Here 1000(milliseconds) means one 1 Sec 
        }
</script>


<body onload="ShowCurrentTime()"> </body>