learned/learning/to learn RSS 2.0
# Wednesday, 30 September 2009

This article describes how to notify users about session expiration and allow them to renew the session.

Controls that need to be added:
1. A Panel with an OK button.

2. A label with session expiration notification message.

3. An AJAX ModalPopupExtender.

4. A dummy button and set ModalPopupExtender’s TargetControlId as this button.

 

This is how it looks:

 

<cc1:ModalPopupExtender ID="modext_promptmessage" runat="server" BehaviorID="popup_promptmessage"

    PopupControlID="pnl_popup" TargetControlID="btn_dummy">

</cc1:ModalPopupExtender>

<asp:Panel ID="pnl_popup" runat="server" Style="display: none">

    <table cellpadding="0" cellspacing="0" border="0">

        <tr valign="top">

            <th>

                Prompt Message

            </th>

        </tr>

        <tr>

            <td>               

                        <label>Your session is going to expire in 2 minutes. Please click OK to renew it."></label>

<asp:Button ID="btn_ok" runat="server" OnClientClick="ResetSession()" Text="OK" />

            </td>

        </tr>

    </table>

</asp:Panel>

 

My code behind class looks like this:

 

   Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

     

      ' checks whether session expired

      If Current.Session.Keys.Count = 0 Then

                        Response.Redirect("sessionexpired.aspx", True)

            Exit Sub

      End If

 

' Javascript function PromptSessionExpiration() will be called 2 minutes before session expiration (120000 milliseconds)

      Dim strExpireSessionScript As String = String.Format("setTimeout('PromptSessionExpiration()', {0}); ", (Me.Session.Timeout * 60000) - 120000)

      Me.Page.ClientScript.RegisterClientScriptBlock(Me.GetType(), "expirescript", strExpireSessionScript, True)

 

   End Sub

 

   ''' This click event will renew the session, need not add any code inside it

   Protected Sub btn_ok_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_ok.Click 

   End Sub

 

 

My javascript:

 

<script language="javascript" type="text/javascript">

 

    function PromptSessionExpiration() {

              // the function below will be triggered at the 125th second

        setTimeout('CheckSessionStatus()', 125000);

        // show popup

        $find('popup_promptmessage').show();

    }

 

    // handles closing popup

    function ResetSession() {

        $find('popup_promptmessage').hide();

    }

 

    // this function will be called if user doesn’t respond to the prompt message

    // which will redirect to sessionexpired page

    function CheckSessionStatus() {

            window.location = “sessionexpired.aspx”;

    }   

  

 </script>

 

Thanks.

Wednesday, 30 September 2009 19:55:52 (GMT Daylight Time, UTC+01:00)  #    Comments [0] -
.NET
# Tuesday, 15 September 2009

This article shows you how to use ASP.NET AJAX PageMethods to perform Create, Read, Update and Delete (CRUD) operations with an HTML table. Here HTML table acts as a light-weight DataGrid.

 

Inorder to make PageMethods work, following things need to be done:

  1. ScriptManager should be added to your ASPX page.
  2. EnablePageMethods property of the ScriptManager should be set to true.
  3. System.Web.Services namespace should be added as reference on your codebehind class.
  4. Page Methods on your code-behind should be decorated with [WebMethod] attribute.

 

First let us start with Read.


As mentioned above, add a ScriptManager and set its 'EnablePageMethods' property to true. Add an HTML button and an onclick handler to it, and then add an HTML table with thead, tbody and tfoot. Since the HTML table will be referenced from javascript, add id to the table and its body. Here, only HTML tags/controls are used because, server side controls cannot be referenced in PageMethods.


Your ASPX page should look something like this.

 

<body>

    <form id="form1" runat="server">   

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

        <%--This click event handles loading data from the database--%>

        <input id="btn_load" type="button" value="Load" onclick = "LoadData()" />

        <br /><br />

    <div>

        <table style=" height: 100%; border: solid 1px #000" cellpadding="0" cellspacing="1" id="tbl_grid" border = "1">

            <thead style = "background-color: #666; color: #fff">

                <tr>

                    <td style="width: 100px;">

                        Column1

                    </td>

                    <td style="width: 500px;">

                        Column2

                    </td>

                    <td style="width: 150px;">

                        Edit

                    </td>

                </tr>

            </thead>

            <tbody id="tbody_grid">

            </tbody>

            <tfoot>

                <tr>

                    <td style="width: 100px;">

                        <input id="txt_addcol1" style ="width: 30px" type="text" />

                    </td>

                    <td style="width: 500px;">

                        <input id="txt_addcol2" type="text"  style ="width: 300px" />

                    </td>

                    <td style="width: 150px;">                   

                        <%--This click event handles adding data to the database--%>

                        <input id="btn_add" type="button" onclick = "Add()" value="Add" />

                    </td>

                </tr>

            </tfoot>

        </table>

    </div>

    </form>

</body>

 

Now add your JavaScript function to load data from the database using PageMethods. PageMethod call should always have a success handler (this will be executed if the page method is executed successfully) and an exception handler (this will be executed if an exception is thrown). Say suppose we added 'GetData()' as the page method on the code behind, our javascript will be PageMethods.GetData(SuccessHandler, ExceptionHandler). Just for understanding, I have named the success and exception handler appropriately, you can name them as you wish. In case, the page methods takes parameters, you can add like PageMethods.GetData(param1, param2, SuccessHandler, ExceptionHandler).

Page methods should be decorated with [WebMethod] attribute and should be declared as static. Its signature shoul look something like this:

[WebMethod]

public static string GetData()


Page method to return data to javascript.


public partial class AJAXGrid : System.Web.UI.Page

{

    protected void Page_Load(object sender, EventArgs e)

    {

 

    }


    [WebMethod]

    public static IEnumerable<MyEntity> GetData()

    {

        try

        {                  

Data fetch part should go here

            // used List, as collections are serializable. See below for MyEntity class

            List<MyEntity> MyEntities = new List<MyEntity>();

 

            MyEntities.Add("1", "abc");

MyEntities.Add("2", "xyz");

MyEntities.Add("3", "pqr");

MyEntities.Add("4", "mno");


return MyEntities; 

}

        catch(Exception ex)

        {

            throw ex;

        }

 

    }
}


MyEntity class

 

public class MyEntity

{

    private string _Column1;

 

    public string Column1

    {

      get { return _Column1; }

      set { _Column1 = value; }

    }

   

    private string _Column2;

 

    public string Column2

    {

      get { return _Column2; }

      set { _Column2 = value; }

    }

 

    public MyEntity(string sCol1, string sCol2)

    {

        _Column1 = sCol1;

        _Column2 = sCol2;

    }

}

 

Javascript function that calls page method and populates the HTML table
 

<script type ="text/javascript" language = "javascript ">

 

//Loading Data

 

    // Handles btn_load click event

    function LoadData() {

 

        // If data was fetched successfully, SuccessHandler will be called; else, ExceptionHandler

        PageMethods.GetData(SuccessHandler, ExceptionHandler);

 

  // Incase parameters need to be passed to PageMethods, you can do like this PageMethods.GetData(param1, param2, SuccessHandler, ExceptionHandler)

 

 

    }

 

    // After fetching the data successfully

    function SuccessHandler(result) {

 

        var tbody = $get("tbody_grid");

        // clear the table

        for (var j = tbody.rows.length; j > 0; j--) {

            tbody.deleteRow(j - 1);

        }

        // populate the table

        for (var i = 0; i < result.length; i++) {

            //two columns fetched from database are sent as parameters

            AddRow(result[i].Column1, result[i].Column2);        

        }

        return true;

    }

 

    // Edit and Delete buttons are added to the rows

    function AddRow(col1, col2) {

        var tbody = $get("tbody_grid");

        var row = document.createElement("tr")

        var td1 = document.createElement("td")

        td1.innerText = col1;

        var td2 = document.createElement("td");

        td2.innerText = col2;

        var td3 = document.createElement("td");

        // add buttons

        var btnEdit = document.createElement('input');

        btnEdit.setAttribute('type', 'button');

        btnEdit.setAttribute('name', 'Edit');

        btnEdit.setAttribute('value', 'Edit');

        // first parentNode represents <td> and the second represents <tr>

        btnEdit.onclick = function() { Edit(this.parentNode.parentNode); };

        var btnDelete = document.createElement('input');

        btnDelete.setAttribute('type', 'button');

        btnDelete.setAttribute('name', 'Delete');

        btnDelete.setAttribute('value', 'Delete');

        btnDelete.onclick = function() { DeleteRow(this.parentNode.parentNode); };

        td3.appendChild(btnEdit);

        td3.appendChild(btnDelete);

        row.appendChild(td1);

        row.appendChild(td2);

        row.appendChild(td3);

        tbody.appendChild(row);       

    }

 

    // Handles exception

    function ExceptionHandler(result) {

    }


After populating the HTML table 



Javascript functions to handle Edit, Update, Delete and Insert:


Editing Data

 

    //  this function handles edit button click

    function Edit(row) {

 

        var col1 = row.childNodes[0].innerText;

        var col2 = row.childNodes[1].innerText;

       

        // populates values in textboxes and displays Update and Cancel buttons

        var editableRow = document.createElement("tr")

        var td1 = document.createElement("td")

        var txtBox1 = document.createElement('input');

        txtBox1.setAttribute('type', 'text');

        txtBox1.setAttribute('name', 'col1');

        txtBox1.setAttribute('value', col1);

        txtBox1.setAttribute('width', 30);

        td1.appendChild(txtBox1);

        var td2 = document.createElement("td");

        var txtBox2 = document.createElement('input');

        txtBox2.setAttribute('width', 300);

        txtBox2.setAttribute('type', 'text');

        txtBox2.setAttribute('name', 'col1');

        txtBox2.setAttribute('value', col2);

        td2.appendChild(txtBox2);

        var td3 = document.createElement("td");

        var btnUpdate = document.createElement('input');

        btnUpdate.setAttribute('type', 'button');

        btnUpdate.setAttribute('name', 'Update');

        btnUpdate.setAttribute('value', 'Update');

        btnUpdate.onclick = function() { Update(this.parentNode.parentNode); };

        var btnCancel = document.createElement('input');

        btnCancel.setAttribute('type', 'button');

        btnCancel.setAttribute('name', 'Cancel');

        btnCancel.setAttribute('value', 'Cancel');

        btnCancel.onclick = function() { Cancel(this.parentNode.parentNode); };

        td3.appendChild(btnUpdate);

        td3.appendChild(btnCancel);

        editableRow.appendChild(td1);

        editableRow.appendChild(td2);

        editableRow.appendChild(td3);

        row.parentNode.replaceChild(editableRow, row);

    }


After edit button click



 

Updating Data

 

    //  this function handles update button click

    function Update(row) {

 

        // fetches values entered in the textboxes

        // first childNode represent <td> inside <tr> and second childNode represents textbox

        var col1 = row.childNodes[0].childNodes[0].value;

        var col2 = row.childNodes[1].childNodes[0].value;

 

        // values sent to server

        PageMethods.UpdateData(col1, col2, UpdateSuccess(row), ExceptionHandler);      

    }

 

    // After updating the values successfully

    function UpdateSuccess(row) {

 

        var col1 = row.childNodes[0].childNodes[0].value;

        var col2 = row.childNodes[1].childNodes[0].value;

 

        var editableRow = document.createElement("tr")

        var td1 = document.createElement("td")

        td1.innerText = col1;

        var td2 = document.createElement("td");

        td2.innerText = col2;

        var td3 = document.createElement("td");

        var btnEdit = document.createElement('input');

        btnEdit.setAttribute('type', 'button');

        btnEdit.setAttribute('name', 'Edit');

        btnEdit.setAttribute('value', 'Edit');

        btnEdit.onclick = function() { Edit(this.parentNode.parentNode); };

        var btnDelete = document.createElement('input');

        btnDelete.setAttribute('type', 'button');

        btnDelete.setAttribute('name', 'Delete');

        btnDelete.setAttribute('value', 'Delete');

        btnDelete.onclick = function() { DeleteRow(this.parentNode.parentNode); };

        td3.appendChild(btnEdit);

        td3.appendChild(btnDelete);

        editableRow.appendChild(td1);

        editableRow.appendChild(td2);

        editableRow.appendChild(td3);

        row.parentNode.replaceChild(editableRow, row);

 

    }

 

    // this function handles cancel button click

    function Cancel(row) {

 

        // values are again populated in labels instead of textboxes

        var col1 = row.childNodes[0].childNodes[0].value;

        var col2 = row.childNodes[1].childNodes[0].value;

 

        var editableRow = document.createElement("tr")

        var td1 = document.createElement("td")

        td1.innerText = col1;

        var td2 = document.createElement("td");

        td2.innerText = col2;

        var td3 = document.createElement("td");

        var btnEdit = document.createElement('input');

        btnEdit.setAttribute('type', 'button');

        btnEdit.setAttribute('name', 'Edit');

        btnEdit.setAttribute('value', 'Edit');

        btnEdit.onclick = function() { Edit(this.parentNode.parentNode); };

        var btnDelete = document.createElement('input');

        btnDelete.setAttribute('type', 'button');

        btnDelete.setAttribute('name', 'Delete');

        btnDelete.setAttribute('value', 'Delete');

        btnDelete.onclick = function() { DeleteRow(this.parentNode.parentNode); };

        td3.appendChild(btnEdit);

        td3.appendChild(btnDelete);

        editableRow.appendChild(td1);

        editableRow.appendChild(td2);

        editableRow.appendChild(td3);

        row.parentNode.replaceChild(editableRow, row);

    }

 

    //  this function handles 'add' button click

    function Add() {

 

        var col1 = $get("txt_addcol1").value;

        var col2 = $get("txt_addcol2").value;

 

        // data sent to the database

        PageMethods.InsertData(col1, col2, AddSuccess(col1, col2), ExceptionHandler);        

 

    }

 

    // After adding the data successfully

    function AddSuccess(col1, col2) {

 

        // add the values to the table

        AddRow(col1, col2);

       

        // clear the textboxes in the footer

        $get("txt_addcol1").value = "";

        $get("txt_addcol2").value = "";

       

    }

 

Deleting Data

 

    // this function handles delete button click

    function DeleteRow(row) {

 

        var col1 = row.childNodes[0].innerText;

        // delete from the database

        PageMethods.DeleteData(col1, DeleteSuccess(row), ExceptionHandler);

    }

 

    function DeleteSuccess(row) {

        // delete the row from the table

        var tbody = $get("tbody_grid");

        tbody.removeChild(row);

    }

   

 

</script>

 

Page methods to handle Edit, Update, Delete and Insert:

           

 

    [WebMethod]

    public static void UpdateData(string sCol1, string sCol2)

    {

  try

        {                  

        Data update part should go here     

        }

        catch(Exception ex)

        {

            throw ex;

        }

 

    }

 

    [WebMethod]

    public static void InsertData(string sCol1, string sCol2)

    {

        try

        {

                          Data insert part should go here        

        }

        catch(Exception ex)

        {

            throw ex;

        }

    }

 

    [WebMethod]

    public static void DeleteData(string sCol1)

    {

        try

        {

                           Data delete part should go here         

        }

        catch (Exception ex)

        {

            throw ex;

        }

    }

}


We can add paging and sorting too.


This code has been tested in IE7+, Firefox, Chrome and Safari.

 

Some of the limitations in using ASP.NET AJAX PageMethods:

1.       We can't access asp.net server controls (like TextBox control) in the WebMethod directly as we normally access in the server side methods.

2.       We can't access any variable declared in the code behind.

Advantage: PageMethods is a simple lightweight way to submit/fetch data to the server using ASP.NET AJAX. This doesn't submit whole page data to the server and also as opposed to the ASP.NET AJAX call back this doesn't even fire the Page_Load and other Page events of the code behind page.




Tuesday, 15 September 2009 20:24:25 (GMT Daylight Time, UTC+01:00)  #    Comments [3] -
.NET
# Saturday, 01 August 2009

As I started getting too many spams because of bots, I implemented Completely Automated Public Turing test to tell Computers and Humans Apart (CAPTCHA) in all the interactive pages of my site.

 

Took the control from here http://www.codeproject.com/KB/custom-controls/CaptchaControl.aspx, and customized according to my needs. The code was easy to understand and customize.

Saturday, 01 August 2009 18:45:44 (GMT Daylight Time, UTC+01:00)  #    Comments [0] -
.NET
# Tuesday, 16 June 2009

I got a chance to work on the below documentation softwares recently, were pretty good. There might be some other softwares better than these, if so, let me know.

  1. SQLSpec – For database documentation, it supports various databases like MS SQL Server, Oracle, Access, DB2, Sybase etc. It is very easy to use, however, customizations like excluding objects and xml commenting took me sometime. It creates MSDN help file style documents. Download link - http://www.elsasoft.org/
  2. SandCastle – Free software, for .NET project documentation. Supports .NET 1.1, 2.0, 3.0 and 3.5.  It is also very easy to use and creates MSDN help file style documents.  Download it from here http://www.codeplex.com/Sandcastle and install it, and then install SandCastle Help File Builder from here http://www.codeplex.com/SHFB

Tuesday, 16 June 2009 18:44:48 (GMT Daylight Time, UTC+01:00)  #    Comments [0] -
.NET | Softwares
# Monday, 01 June 2009

You can add your own configuration sections in Web.config or App.config file. There might be some good way to do it, if so, please let me know.

 

Step 1

Add the follwing inside <configSections> tag:

<configSections>

    <section name ="customSection" type ="System.Configuration.NameValueSectionHandler"/>

</configSections>

 

Step 2

Add your custom section before or after <appSettings> but after <configSections>

<customSection>

  <add key="key1" value="value1" />

  <add key="key2" value="value2" />

</customSection>

 

Your app.config will be like this

 ---------------------------------------------------------------------------------------------------------------

<?xml version="1.0" encoding="utf-8"?>

<configuration>

  <configSections>

      <section name ="customSection" type ="System.Configuration.NameValueSectionHandler"/>

  </configSections>

 

  <!--<Custom Seciton>-->

<customSection>

  <add key="key1" value="value1" />

  <add key="key2" value="value2" />

</customSection>

 

 <appSettings>

    <add key="tesing" value="abc" />

 </appSettings>

 

  <system.web>

  </system.web>

</configuration>

  --------------------------------------------------------------------------------------------------------------

Step 3

How to access it?

 

NameValueCollection colCustomSection = (NameValueCollection)ConfigurationManager.GetSection("customSection");

string key, value;

 

for (int count = 0; count < colCustomSection.Count; count++)

{

   // we can get the keys

   key = colCustomSection.GetKey(count);

   // we can get the values

   value = colCustomSection.Get(count);

 

}

 

 

To add multiple sections

 

Add this inside <configSections>

<configSections>

<sectionGroup name ="customSectionGroup">

    <section name ="customSection1" type ="System.Configuration.NameValueSectionHandler"/>

    <section name ="customSection2" type ="System.Configuration.NameValueSectionHandler"/>

</sectionGroup>

</configSections>

 

Add this around your custom section:

<customSectionGroup>

<customSection1>

  <add key="key1" value="value1" />

  <add key="key2" value="value2" />

</customSection1>

<customSection2>

  <add key="key1" value="value1" />

  <add key="key2" value="value2" />

</customSection2>

</customSectionGroup>

 

To access it, just change the path:

NameValueCollection colCustomSection = (NameValueCollection)ConfigurationManager.GetSection("customSectionGroup/customSection1");

 

customSectionGroup/customSection1 or customSectionGroup/customSection2

 

Monday, 01 June 2009 18:43:34 (GMT Daylight Time, UTC+01:00)  #    Comments [0] -
.NET
# Wednesday, 27 May 2009

Feature 1 - Face recognition: Though this feature was released on 9/02/2008, I noticed it only recently. Worth trying it!

 

How to use it?

  • Log into Picasa Web Album, go to Settings (top right corner) page, you will be able to find a section ‘Name Tags’, and right below it there should be a button ‘Turn name tags ON’, click it. After few seconds Picasa will start auto face recognition, you should be able to see the progress on the right side of your picasa home page.
  • Once it is done, you can click a photo (your photo or any of your friend’s photos) from any of your albums, picasa will show a rectangle around the face of the person in the photo, you can add a name tag.
  • Now, go to ‘People’ tab and add more name tags. See below video for more info.



 

Feature 2 – Email Upload: You can upload photos to your album by forwarding emails addressed to your picasa emailid. You will be able to add a picasa emailid on Settings page, under ‘Upload Photos by Email’ section.

 

Feature 3 – Meta tag info: I think this was there since picasa was introduced, but I came to know this only recently from one of my friends. I added few web albums and sent the links to my friend; he was able to tell the camera that was used to take the photographs, apertures, focal length etc. Picasa reads the meta tag info of the photo and displays on the right hand side of the photo under ‘Photo Information’, click link more info.

Wednesday, 27 May 2009 18:42:08 (GMT Daylight Time, UTC+01:00)  #    Comments [0] -
Miscellaneous | Softwares
# Tuesday, 12 May 2009

I'll usually set my font-sizes in units of 'pt', but this gave me weird results when I increased my monitor's DPI from 96 to 120 (as all the fonts were too small in my HD wide-screen monitor, I increased it). I was doing some research on this and I came across this article, this article clearly explains the right unit to use while developing websites. Though this article says percent (%) is the best, I have used 'px', as it gave me consistent results in IE, Mozilla and Chrome.

Click here to see the article.

You can use the below chart for conversion:

Points Pixels Ems Percent
6pt 8px 0.5em 50%
7pt 9px 0.55em 55%
7.5pt 10px 0.625em 62.5%
8pt 11px 0.7em 70%
9pt 12px 0.75em 75%
10pt 13px 0.8em 80%
10.5pt 14px 0.875em 87.5%
11pt 15px 0.95em 95%
12pt 16px 1em 100%
13pt 17px 1.05em 105%
13.5pt 18px 1.125em 112.5%
14pt 19px 1.2em 120%
14.5pt 20px 1.25em 125%
15pt 21px 1.3em 130%
16pt 22px 1.4em 140%
17pt 23px 1.45em 145%
18pt 24px 1.5em 150%
20pt 26px 1.6em 160%
22pt 29px 1.8em 180%
24pt 32px 2em 200%
26pt 35px 2.2em 220%
27pt 36px 2.25em 225%
28pt 37px 2.3em 230%
29pt 38px 2.35em 235%
30pt 40px 2.45em 245%
32pt 42px 2.55em 255%
34pt 45px 2.75em 275%
36pt 48px 3em 300%

Tuesday, 12 May 2009 18:40:36 (GMT Daylight Time, UTC+01:00)  #    Comments [0] -
HTML
# Tuesday, 05 May 2009

One of my friends forwarded this article to me sometime in 2007, as it was too lengthy, I didn’t read at that time, and few months back I got a chance to read this; only then I realized I should have read this in 2007 itself, because this article had changed my life in many ways since I read this … hope it will change yours too!

 

Author: Stephen Covey

Discover the 90/10 Principle. It will change your life (at least the way you react to situations).

 

What is this principle? 10% of life is made up of what happens to you. 90% of life is decided by how you react.

 

What does this mean? We really have no control over 10% of what happens to us. We cannot stop the car from breaking down. The plane will be late arriving, which throws our whole schedule off. A driver may cut us off in traffic.

 

We have no control over this 10%. The other 90% is different. You determine the other 90%. How? ……….By your reaction. You cannot control a red light. but you can control your reaction. Don't let people fool you; YOU can control how you react.

 

Let's use an example.

You are eating breakfast with your family. Your daughter knocks over a cup of coffee onto your business shirt. You have no control over what just happened. What happens next will be determined by how you react. You curse. You harshly scold your daughter for knocking the cup over. She breaks down in tears. After scolding her, you turn to your spouse and criticize her for placing the cup too close to the edge of the table. A short verbal battle follows. You storm upstairs and change your shirt. Back downstairs, you find your daughter has been too busy crying to finish breakfast and get ready for school. She misses the bus. Your spouse must leave immediately for work. You rush to the car and drive your daughter to school. Because you are late, you drive 40 miles an hour in a 30 mph speed limit. After a 15-minute delay and throwing $60 traffic fine away, you arrive at school. Your daughter runs into the building without saying goodbye. After arriving at the office 20 minutes late, you find you forgot your briefcase. Your day has started terrible. As it continues, it seems to get worse and worse. You look forward to coming home. When you arrive home, you find small wedge in your relationship with your spouse and daughter. Why? …. Because of how you reacted in the morning.

 

Why did you have a bad day?

A) Did the coffee cause it?

B) Did your daughter cause it?

C) Did the policeman cause it?

D) Did you cause it?

 

The answer is “D".

You had no control over what happened with the coffee. How you reacted in those 5 seconds is what caused your bad day.

 

Here is what could have and should have happened. Coffee splashes over you. Your daughter is about to cry. You gently say, "Its ok honey, you just need to be more careful next time". Grabbing a towel you rush upstairs. After grabbing a new shirt and your briefcase, you come back down in time to look through the window and see your child getting on the bus. She turns and waves. You arrive 5 minutes early and cheerfully greet the staff. Your boss comments on how good the day you are having. Notice the difference? Two different scenarios. Both started the same. Both ended different. Why? Because of how you REACTED. You really do not have any control over 10% of what happens. The other 90% was determined by your reaction.

 

Here are some ways to apply the 90/10 principle. If someone says something negative about you, don't be a sponge. Let the attack roll off like water on glass. You don't have to let the negative comment affect you! React properly and it will not ruin your day. A wrong reaction could result in losing a friend, being fired, getting stressed out etc. How do you react if someone cuts you off in traffic? Do you lose your temper? Pound on the steering wheel? A friend of mine had the steering wheel fall off) Do you curse? Does your blood pressure skyrocket? Do you try and bump them? WHO CARES if you arrive ten seconds later at work? Why let the cars ruin your drive? Remember the 90/10 principle, and do not worry about it. You are told you lost your job. Why lose sleep and get irritated? It will work out. Use your worrying energy and time into finding another job. The plane is late; it is going to mangle your schedule for the day. Why take outpour frustration on the flight attendant? She has no control over what is going on. Use your time to study, get to know the other passenger. Why get stressed out? It will just make things worse.

 

Now you know the 90-10 principle. Apply it and you will be amazed at the results. You will lose nothing if you try it. The 90-10 principle is incredible. Very few know and apply this principle. The result? Millions of people are suffering from undeserved stress, trials, problems and heartache. We all must understand and apply the 90/10 principle.

 

It CAN change your life!!!

Enjoy….

Tuesday, 05 May 2009 18:38:40 (GMT Daylight Time, UTC+01:00)  #    Comments [0] -
Miscellaneous
# Friday, 01 May 2009

This works in Oracle, hope there is something similar to this in Sql Server too! There might be some other good way to do this, if so, please let me know.

SELECT * FROM TABLE1 WHERE COLUMN1 IN (‘ABC’,’XYZ’,’PQR’) 

Say suppose the strings ‘ABC’,’XYZ’ and ’PQR’ need to be grouped as a single string in the frontend and to be passed as a parameter.  How can we do it? We cannot write like this –

SELECT * FROM TABLE1 WHERE COLUMN1 IN (IN_PARAMTER)

There are many ways to do it:

  1. We can write an inline query.
  2. We can split the strings and group it as a table type.
  3. We can write dynamic sql.

There is one more way to do it and found it to be easy, so thought of sharing.

Here it is:

SELECT * FROM TABLE1 WHERE COLUMN1 IN
(          
 SELECT  REGEXP_SUBSTR(In_Parameter ,'[^,]+',1,LEVEL)        
 FROM    DUAL
 CONNECT BY LEVEL <= LENGTH (REGEXP_REPLACE (In_Parameter, '[^,]')) + 1
)
 

It is enough if we pass the parameter as ‘ABC,XYZ,PQR’ instead of “‘ABC’,’XYZ’,’PQR’”.

More about Oracle Regular Expressions - http://download-west.oracle.com/docs/cd/B13789_01/server.101/b10759/functions116.htm

Friday, 01 May 2009 18:33:29 (GMT Daylight Time, UTC+01:00)  #    Comments [0] -
Oracle
# Thursday, 16 April 2009

Select or Insert or Update or Delete rows in Excel using .NET. i.e., CRUD operations in EXCEL using .NET. We can literally use the excel sheet as a database, just the connection string matters. Note: 1. This code cannot be used for password protected excel sheets. 2. Delete does not work. See below for explanations. There might be some other good way to do this, if so, let me know.

 

Insert a row in an excel sheet

 

protected void btn_create_Click(object sender, EventArgs e)

{

    OleDbConnection objConnection;

    OleDbCommand objCommand;

    OleDbParameter objParameter;

 

    // Here HDR= YES represents that header is present

    // If the excelsheet you are dealing with does not have header, you can mention HDR = NO,

    // and while fetching columns you have to mention F1, F2 rather than the column names

    objConnection = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=D:\Excel\CRUD_EXCEL.xls;

                                                                                                            Extended Properties=""Excel 8.0;HDR=YES;""");

    objCommand = new OleDbCommand();

 

    objCommand.Connection = objConnection;

    objCommand.CommandType = CommandType.Text;

 

    // The sheet name should be followed by $ sign

    objCommand.CommandText = "INSERT INTO [SHEETNAME$](COLUMN_INT, COLUMN_VARCHAR) VALUES(@COLUMN_INT, @COLUMN_VARCHAR)";

 

    objParameter = new OleDbParameter("@COLUMN_INT", OleDbType.Integer);

    objParameter.Value = 3;

    objCommand.Parameters.Add(objParameter);

 

    objParameter = new OleDbParameter("@COLUMN_VARCHAR", OleDbType.VarChar);

    objParameter.Value = "testing";

    objCommand.Parameters.Add(objParameter);

 

    objConnection.Open();

    objCommand.ExecuteNonQuery();

    objConnection.Close();

}

 

Select rows in an Excel sheet

 

protected void btn_read_Click(object sender, EventArgs e)

{

    OleDbConnection objConnection;

    OleDbCommand objCommand;

    OleDbParameter objParameter;

 

    // Here HDR= YES represents that header is present

    // If the excelsheet you are dealing with does not have header, you can mention HDR = NO,

    //and while fetching columns you have to mention F1, F2 rather than the column names

    objConnection = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=D:\Excel\CRUD_EXCEL.xls;

                                                                                                                Extended Properties=""Excel 8.0;HDR=YES;""");

    objCommand = new OleDbCommand();

 

    objCommand.Connection = objConnection;

    objCommand.CommandType = CommandType.Text;

 

    // If the excel sheet you are dealing with does not have header, your query will be SELECT F1, F2 FROM [SHEETNAME$]

    objCommand.CommandText = "SELECT COLUMN_INT as COLUMN1, COLUMN_VARCHAR AS COLUMN2 FROM [SHEETNAME$]";

 

    objDataAdapter = new OleDbDataAdapter();

    objDataSet = new DataSet();

    objDataAdapter.SelectCommand = objCommand;

 

    objConnection.Open();

    objDataAdapter.Fill(objDataSet);

    objConnection.Close();

}

 

Update a row in an excel sheet

 

protected void btn_update_Click(object sender, EventArgs e)

{

    OleDbConnection objConnection;

    OleDbCommand objCommand;

    OleDbParameter objParameter;

 

    // Here HDR= YES represents that header is present

    // If the excelsheet you are dealing with does not have header, you can mention HDR = NO,

    // and while fetching columns you have to mention F1, F2 rather than the column names

    objConnection = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=D:\Excel\CRUD_EXCEL.xls;

                                                                                                            Extended Properties=""Excel 8.0;HDR=YES;""");

    objCommand = new OleDbCommand();

 

    objCommand.Connection = objConnection;

    objCommand.CommandType = CommandType.Text;

 

    objCommand.CommandText = "UPDATE [SHEETNAME$] SET COLUMN_VARCHAR =  @COLUMN_VARCHAR WHERE COLUMN_INT = @COLUMN_INT";

 

    objParameter = new OleDbParameter("@COLUMN_VARCHAR", OleDbType.VarChar);

    objParameter.Value = "PQR";

    objCommand.Parameters.Add(objParameter);

 

    objParameter = new OleDbParameter("@COLUMN_INT", OleDbType.Integer);

    objParameter.Value = 3;

    objCommand.Parameters.Add(objParameter);

 

    objConnection.Open();

    objCommand.ExecuteNonQuery();

    objConnection.Close();

}

 

Delete

 

protected void btn_delete_Click(object sender, EventArgs e)

{

        As far as I know ADO does not support Excel row delete

 

        You are more restricted in deleting Excel data than data from a relational data source.

        In a relational database, "row" has no meaning or existence apart from "record";

        in an Excel worksheet, this is not true. You can delete values in fields (cells). However, you cannot:

 

        1. Delete an entire record at once or you receive the following error message:

            Deleting data in a linked table is not supported by this ISAM.

            You can only delete a record by blanking out the contents of each individual field.

        2. Delete the value in a cell containing an Excel formula or you receive the following error message:

            Operation is not allowed in this context.

        3. You cannot delete the empty spreadsheet row(s) in which the deleted data was located,

            and your recordset will continue to display empty records corresponding to these empty rows.

}

 

Thursday, 16 April 2009 18:10:39 (GMT Daylight Time, UTC+01:00)  #    Comments [0] -
.NET
Navigation
Archive
<2009 September>
SunMonTueWedThuFriSat
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2017
Gokulnath
Sign In
Statistics
Total Posts: 41
This Year: 0
This Month: 0
This Week: 0
Comments: 47
Themes
Pick a theme:
All Content © 2017, Gokulnath
DasBlog theme 'Business' created by Christoph De Baene (delarou)

The bulk of humans who will end up affairs Artya's expensive, bound assembly articles are small. These are mostly flush collectors who accept omega replica an aberrant yield on activity and are annihilation but amateur watch lovers. After a lifetime of affairs or seeing bourgeois timepieces, for abounding it can be abundantly auspicious to rolex replica don something weird, wild, or just apparent controversial. We feel that it is our role as a watch media destination not alone to acquaint with those alcove buyers who abide our breitling replica admired readership forth with anybody else, but aswell to bell ross replica accumulate humans abreast of what is new and potentially discussion-worthy in the archival world.