Search This Blog

Thursday, February 6, 2014

RIGHT function SQL Server Example

SQL Server > Built-in Functions > RIGHT

Returns the right part of a string with the specified number of characters.

Example:

declare @str nvarchar(max)
set @str='SQL Server'
select right(@str,6)

Result:
Server
 
 





Tuesday, February 4, 2014

Using jQuery ajax to call asmx WebService methods

ASP.NET > WebService > jQuery

Using jQuery ajax to call asmx WebService methods

Example:




Code:

WebService1.asmx

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;

namespace JQuery
{
    ///



    /// Summary description for WebService1
    ///
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
    // [System.Web.Script.Services.ScriptService]
    public class WebService1 : System.Web.Services.WebService
    {
        [WebMethod]
        public string GetCode(string name)
        {
            return "Code for " + name + " is " + "1111";
        }
    }
}

HtmlPage1.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
        <script src="jquery-2.1.0.min.js" type="text/javascript"></script>
</head>

<body>
    <form id="form1" runat="server">
    <div><br />Access Code</div>
    <div id="code"></div>

    <script type="text/javascript">
        $(document).ready(function () {
            $.ajax({
                type: "POST",
                url: "WebService1.asmx/GetCode",
                data: "name=John",
                dataType: "text",
                success: function (data) {
                    $("#code").html(data);
                }
            });
        });
    </script>
    </form>
</body>
</html>

Monday, February 3, 2014

Difference between Clone() and Copy() method C#

C# > String > Clone and Copy

Clone will copy the structure of a data 
Copy will copy the complete structure and data.

Example:
Difference between Clone() and Copy() method

string[] arr1 = { "a", "b", "c" };
string[] arr2 = arr1; //copy
string[] arr3 = (string[])arr1.Clone();
arr2[0] = "x";
MessageBox.Show(arr1[0] + "," + arr2[0] + "," + arr3[0]);





C# String Class

C# > String class

Represents text as a series of Unicode characters.
Examples




LEFT SQL Server Example

SQL Server > Built-in Functions > LEFT

Returns the left part of a string with the specified number of characters.

Example:

declare @str nvarchar(max)
set @str='SQL Server'
select left(@str,3)

result:
SQL




LEN SQL Server Example

SQL Server > Built-in Functions > LEN

Returns then length of string expression.

Example

declare @str nvarchar(max)

set @str='SQL Server'

select Len(@str)

result:
10




Thursday, January 30, 2014

HOST_NAME SQL Server Example

SQL Server > Built-In Functions > HOST_NAME


Represents the workstation name, name of computer connected to SQL Server.

SELECT HOST_NAME()