Friday, January 29, 2010

Formatting as Currency

If you need to format a number as currency, do this:

declare @d money set @d=50000.52
select '$' + convert(varchar(50), @d,1)

Result: $50,000.52

Though it should be noted that usually, formatting is a front-end task, and should not to be relegated to the database as a matter of best practice.

Wednesday, January 06, 2010

How to Install Windows Service

This article was very helpful in showing how to create an installer file for a widows service application.

Monday, November 09, 2009

SyntaxHighlighter

SyntaxHighlighter is a fully functional self-contained code syntax highlighter

This is an example usage of syntax highlighting:

This is a block of SQL:
 --this is a comment
 Select * from tableName where Iam='you'
 and my='crazy' and theyAre=false
 and thisIs like 'this or that%'
 
This is a block of C# code:
 //This is a commment... just a comment
 private void DoSomething()
 {
  return null;
 }
 

Here is a simple example which will work so long as you don't have complex html (in that case see the documentation):

    
     //This is a commment... just a comment
     private void DoSomething()
     {
      return null;
     }
     

Wednesday, November 04, 2009

Sample ASP.NET AJAX

This is application shows an example of calling a web service from ASP.NET AJAX web-service. Here's what you will need to do: 1) Create a web service. This is a class which references the following namespaces in

using System;

using System.Collections.Generic;

using System.Web;

using System.Web.Services;

namespace EliasNameSpace

{

[WebService(Namespace = "http://tempuri.org/")]

[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]

[System.Web.Script.Services.ScriptService] //allow javascript calls public class TestService : System.Web.Services.WebService

{

[WebMethod]

public string HelloWorld()

{

return "Hello World";

}

}

}

2) Reference the web service in your page

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

<Services><asp:ServiceReference Path="~/TestService.asmx" />Services>

asp:ScriptManager>

3) Call the webservice in your javascript code

function onSuccess(result, context, methodName) {

var str ="Success. Your result is: " + result;

str += "

Context: " + context + " "

+ "methodName: " + methodName + "";

$get("msgDiv").innerHTML += str;

}

function onFail(errror, context, methodName) {

var str = "Failed. Error: " + errror;

str += "

Context: " + context + " "

+ "methodName: " + methodName + "";

$get("msgDiv").innerHTML += str;

}

//this calls the webservice, onSuccess is the function called if it succeeded, onFail is called if it failed.

EliasNameSpace.TestService.HelloWorld(onSuccess, onFail);

If you'd like a working example: Download Sample Ajaxed Web Service Application

Tuesday, November 03, 2009

There is honor to be had

There is honor in the sweat that an honest living demands.