Wednesday, December 1, 2010

N2 and F2 format for Decimal Places

For formatting 2 decimal places, you can use N2 and F2

Dim nNumber As Decimal = 12004587.123000

Console.WriteLine("F2: " & nNumber.ToString("F2"))
Console.WriteLine("N2: " & nNumber.ToString("N2"))

Output:

F2: 12004587.12
N2: 12,004,587.12

Sunday, November 21, 2010

Return 2 decimal places without rounding

This function returns 2 decimal places without rounding. This function requires to pass decimal value parameter.


private string FormatDecimal(decimal val)
{
decimal newValue = ((Int64)(val * 100)) / 100m;
return newValue.ToString("N2");
}


for example:

decimal dValue = 22221111.8055234M;
string newValue = FormatDecimal(dValue);


Output:
newValue = 22,221,111.80

Monday, August 30, 2010

Query SysObjects

select * from sysobjects
- returns all Objects in a database (e.g. tables, Views, Stored Procedures)


select * from sysobjects where type = 'U'
- returns all Tables Objects


select * from sysobjects where type = 'V'
- returns all SQL Views Objects


select * from sysobjects where type = 'P'
- returns all SQL Stored Procedure Objects

Thursday, September 18, 2008

System.UnauthorizedAccessException: Access to the path "e:\Inetpub\wwwwroot11\Project\Dumpfile.xls" is denied









Solution:
1.) Go the specific folder that contains the file
2.)Right-click the folder and click Properties
3.) Go to Security tab then look for Network Service user. Modify permissions within the folder .
4.)Lastly, Click OK































Thursday, August 21, 2008

C# - Split Sample


string _approvers = "allan;che;paul";

char[] delimiterChars = { ';' };
string[] arrVar = _approvers.Split(delimiterChars);

for(int x = 0; x < arrVar.Length; x++)
{
Response.Write(arrVar [x] );
}

Wednesday, July 30, 2008

Export Data List to Excel

Response.Clear();
Response.Buffer= true;
Response.ContentType = "application/vnd.ms-excel";
Response.Charset = "";
this.EnableViewState = false;System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
this.ClearControls(DataGridView);DataGridView.RenderControl(oHtmlTextWriter);
Response.Write(oStringWriter.ToString());
Response.Flush();
Response.End();

Tuesday, June 3, 2008

SQL Joins

Joins

Syntax:
SELECT field1, field2, field3 FROM firsttable
INNER JOIN secondtable
ON firsttable.keyfield = secondtable.foreign_keyfield

Example:
SELECT Purchase.Name, Orders.Product FROM Purchase
INNER JOIN Orders
ON Purchase.PurchaseID=Orders.PurchaseID

Left Join

syntax:
SELECT field1, field2, field3 FROM firsttable
LEFT JOIN secondtable
ON firsttable.keyfield = secondtable.foreign_keyfield

Example
SELECT Purchase.Name, Orders.Product
FROM Purchase LEFT JOIN Orders
ON Purchase.PurchaseID=Orders.PurchaseID

Left Join- returns all the rows from the first table (Purchase), even if there are no matches in the second table (Orders). If there are rows in Employees that do not have matches in Orders, those rows also will be listed.

RIGHT JOIN

syntax
SELECT field1, field2, field3
FROM firsttable
RIGHT JOIN secondtable
ON firsttable.keyfield = secondtable.foreign_keyfield

Example
SELECT Purchase.Name, Orders.Product
FROM Purchase
RIGHT JOIN Orders
ON Purchase.PurchaseID=Orders.Purchase