Adds

Saturday, 20 September 2014

How to Title Case a Column Value Using SQL Query

Create a scalar-valued functions in database,

CREATE FUNCTION dbo.fn_title_case
(
  @str AS varchar(100)
)
RETURNS varchar(100)
AS
BEGIN

  DECLARE
    @ret_str AS varchar(100),
    @pos AS int,
    @len AS int

  SELECT
    @ret_str = ' ' + LOWER(@str),
    @pos = 1,
    @len = LEN(@str) + 1

  WHILE @pos > 0 AND @pos < @len
  BEGIN
    SET @ret_str = STUFF(@ret_str,
                         @pos + 1,
                         1,
                         UPPER(SUBSTRING(@ret_str,@pos + 1, 1)))
    SET @pos = CHARINDEX(' ', @ret_str, @pos + 1)
  END

  RETURN RIGHT(@ret_str, @len - 1)


END

======

Execute this update sql query

UPDATE dbo.Client
  SET ClientName = dbo. fn_title_case(ClientName)

Tuesday, 2 September 2014

Allow only number in C# TextBox using JavaScript


C# Control:

<asp:TextBox CssClass="form-control" ID="txtContactNumber" runat="server" onkeypress="return isNumber(event)"></asp:TextBox>

JavaScript:

function isNumber(evt) {
            evt = (evt) ? evt : window.event;
            var charCode = (evt.which) ? evt.which : evt.keyCode;
            if (charCode > 31 && (charCode < 48 || charCode > 57)) {
                return false;
            }
            return true;
        }

Thursday, 6 March 2014

Display Image in asp.net C# web form after click file upload using Javascript

Javascript:

<script type="text/javascript">
    function previewFile() {
        var preview = document.querySelector('#<%=Avatar.ClientID %>');
        var file = document.querySelector('#<%=avatarUpload.ClientID %>').files[0];
        var reader = new FileReader();

        reader.onloadend = function () {
            preview.src = reader.result;
        }

        if (file) {
            reader.readAsDataURL(file);
        } else {
            preview.src = "";
        }
    }
    </script>

 .aspx page code:

    <p>
        <asp:Image ID="Avatar" runat="server" Height="225px" ImageUrl="~/Images/NoUser.jpg" Width="225px" />
    </p>
    <p>
        <input ID="avatarUpload" type="file" name="file" onchange="previewFile()"  runat="server" />
        <asp:Button ID="btnUpload" runat="server" Text="Upload" OnClick="Upload"/>   
    </p>

Tuesday, 4 March 2014

Open a .aspx page on a new tab in asp.net button click event using javascript

Code For .aspx page:

<asp:Button ID="btnAbout" runat="server" Text="About" onclick="btnAbout_Click" OnClientClick="return PostToNewWindow();"/>


Java Script Function:

<script type="text/javascript">
    function PostToNewWindow() {
        originalTarget = document.forms[0].target;
        document.forms[0].target = '_blank';
        window.setTimeout("document.forms[0].target=originalTarget;", 300);
        return true;
    }
</script>


Code in .cs Page For Button Click:

protected void btnAbout_Click(object sender, EventArgs e)
{
Response.Redirect("~/About.aspx");
}

That's It.

Friday, 24 January 2014

Table Column Sum using LINQ with Where Clause

var res = (from x in dbcon.tbl_R_Bill
                where x.PartsSalesOrderSL == id
                select x.PaidAmount).Sum();

txtTotalPaidAmount.Text = res.ToString();

Sunday, 12 January 2014

Conditional count in Crystal Report XI

My Table Structure is this.
Now we will count how many student are passed & failed in the report footer. Look Like This
For This Output We need to use a Running Total Field.

Create a running total
>> Field to summarize : Result.Use Count for field.
Under Evaluate section: select "Use a formula".
Click on the icon next to this and write {result}='pass'.
Then it will only calculate the number of students Passed.
The same way applies to find the count of Failed students.