Search This Blog

Thursday, February 13, 2014

ABS SQL Server Example

SQL Server > Built-in Functions > ABS

Returns the absolute positive value of a numeric expression.

Example

DECLARE @i int;
SET @i = -333;
SELECT ABS(@i);

Result:
333


 
 





Power SQL Server Example

SQL Server > Built-in Functions > POWER

Returns the value of a number to the specified power.

Example:

select power(2,4)

Result:

16
 
 






Wednesday, February 12, 2014

ORA_ROWSCN Oracle example

Oracle

ORA_ROWSCN returns the conservative upper bound system change number (SCN) of the most recent change to the row. This is useful for determining approximately when a row was last updated.

Example

Get the system change number of the last operation on the items table

SELECT ORA_ROWSCN, item_name FROM items WHERE item_id = 10;




Friday, February 7, 2014

Convert binary data to MemoryStream C#

C# > IO > MemoryStream

Creates a stream whose backing store is memory.

Example:

Convert binary data to MemoryStream

public MemoryStream GetMemoryFile(System.Data.Linq.Binary image)
{   
   return new MemoryStream(image.ToArray());
}




Thursday, February 6, 2014

SPACE SQL Server Example

SQL Server > Built-in Functions > SPACE

Returns a string of repeated spaces.

Example:

declare

@str nvarchar(max),
@str1 nvarchar(max)

set @str='SQL'
set @str1='SERVER'

select @str + SPACE(5) + @str1


Result:
SQL     SERVER
 
 





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>