Convert Number to Word In SQL Sever

September 20, 2016 Leave a comment

Hi all,

Try this example to convert number to word in SQL Server


Create FUNCTION [dbo].[NumberToWords]
(
@Amount bigint
)
RETURNS nvarchar(max)
AS
BEGIN
declare @Ones table (Id int, Name nvarchar(50))
declare @Decades table (Id int, Name nvarchar(50))
insert into @Ones(Id,Name) values(0,''),(1,'One'),
(2,'Two'),(3,'Three'),(4,'Four'),(5,'Five'),
(6,'Six'),(7,'Seven'),(8,'Eight'),(9,'Nine'),
(10,'Ten'),(11,'Eleven'),(12,'Twelve'),(13,'Thirteen'),
(14,'Forteen'),(15,'Fifteen'),(16,'Sixteen'),
(17,'Seventeen'),(18,'Eighteen'),(19,'Nineteen')
insert into @Decades(Id,Name) values(20,'Twenty'),(30,'Thirty'),
(40,'Forty'),(50,'Fifty'),(60,'Sixty'),
(70,'Seventy'),(80,'Eighty'),(90,'Ninety')
declare @str nvarchar(max)
set @str=''

if(@Amount >= 1 AND @Amount <20)
set @str=@str+ (select Name from @Ones where Id=@Amount)

if(@Amount >= 20 AND @Amount <=99)
set @str=@str+ (select Name From @Decades where Id=
(@Amount- @Amount%10))+' ' +(select Name From @Ones where Id=(@Amount%10)) +' '

if(@Amount >= 100 AND @Amount <=999)
set @str=@str+ dbo.NumberToWords(@Amount/100) +'
Hundred '+dbo.NumberToWords(@Amount%100)

if(@Amount >= 1000 AND @Amount <=99999)
set @str=@str+ dbo.NumberToWords(@Amount/1000) +'
Thousand '+dbo.NumberToWords(@Amount%1000)

if(@Amount >= 100000 AND @Amount <=9999999)
set @str=@str+ dbo.NumberToWords(@Amount/100000) +'
Lac '+dbo.NumberToWords(@Amount%100000)

if(@Amount >= 10000000 )
set @str=@str+ dbo.NumberToWords(@Amount/10000000) +'
Crore '+dbo.NumberToWords(@Amount%10000000)

return @str
END

Hope this helps

Good Luck.

Categories: SQL Server

List the Name of the Months Between Date Ranges in SQL Server

August 29, 2016 Leave a comment

Hi all,

Try this example to List the Name of the Months Between Date Ranges in SQL Server


DECLARE @sDate DATETIME = '20160301', @eDate DATETIME = '20160901';

;WITH cte AS
(
SELECT @sDate AS dates
UNION ALL
SELECT DATEADD(mm,1,c.dates)
FROM cte c
WHERE c.dates < @eDate
)
SELECT DATENAME(MM, dates)
FROM cte

Hope this helps

Good Luck.

Categories: SQL Server

Allow User to Enter Arabic Characters Or Number Only

July 24, 2016 Leave a comment

Dear all,

Try this example to Validate User to enter Arabic characters or numbers only

<asp:TextBox ID="txt_Name" runat="server"></asp:TextBox>
<asp:RegularExpressionValidator ID="rev_Name" runat="server" ErrorMessage="*" ControlToValidate="txt_Name" ValidationExpression="^[0-9\u0600-\u06FF/ ]+$" ></asp:RegularExpressionValidator>

Hope this helps

Good Luck.

Categories: ASP.Net

Set Maximum characters to 1000 for Multiline TextBox Using JQuery

July 22, 2016 Leave a comment

Hi all,

Try this example to Set Maximum characters to 1000 for Multiline TextBox Using JQuery


<script src="https://code.jquery.com/jquery-1.11.3.js"></script>
 <script type="text/javascript">
 $(document).ready(function () {
 //Assign the text to span in pageload
 $('#spntxtMult').text("Number of characters 0/1000");
 //attach change event to div
 $('#txtMult').keyup(function (event) {
 //call function to calcualate count on change event of div
 textCounter();
 });
 });
 function textCounter() {
 //Get the max length countnt
 var divlength = $('#txtMult').val().length;
 //check if count greater than 1000
 if (divlength > 1000) {
 //Trim the text
 var trimmedtext = $('#txtMult').val().substring(0, 1000);
 //assign it to textbox
 $('#txtMult').val(trimmedtext);
 }
 else {
 var remaningchar = 0;
 //Calculate the remining char
 if (divlength > 0) {
 remaningchar = 1000 - divlength;
 }

//reduce the allowed no of characters in span
 $('#spntxtMult').text("Number of characters " + remaningchar + "/1000");
 }
 }
</script>
<asp:TextBox ID="txtMult" runat="Server" TextMode="MultiLine" />
<span id="spntxtMult"></span>

Hope this helps

Good Luck.

Categories: ASP.Net, Javascript, Jquery

Debug ASP.NET Web Application hosted in IIS using Visual Studio

Hi all,

Try this example to Debug ASP.NET Web Application hosted in IIS using Visual Studio

1. Click the Tools menu in Visual Studio and click the item Attach Process.

Debug-IIS-ASP-Application

2. Search through the Available Processes with the name w3wp.exe.

Debug-IIS-Hosted-ASP-Application

3. Click the Attach button. Now you can watch your break point while doing relevant action in web page

Hope this helps

Good Luck

Categories: ASP.Net

Create An Error Log File

Hi all,

Try this example to Create an error log file

Step 1: Add a Global.asax file to Project/website if not exist.

Step 2: Now add the namespace to Global.asax file.

<%@ Import Namespace="System.IO" %>

Step 3: After that write the below given code in Application_Error event of Global file:

void Application_Error(object sender, EventArgs e)
{
// Code that runs when an unhandled error occurs
Exception ex = new Exception();
ex = Server.GetLastError().GetBaseException();
FileStream fs = new FileStream(Server.MapPath("~/ErrorLOG.txt"), FileMode.OpenOrCreate, FileAccess.ReadWrite);
StreamWriter sw = new StreamWriter(fs);
sw.BaseStream.Seek(0, System.IO.SeekOrigin.End);
sw.WriteLine("ERROR DATE: " + System.DateTime.Now.ToString(System.Globalization.CultureInfo.InvariantCulture));
sw.Write("\r\n");
sw.Write("ERROR MESSAGE: " + ex.Message);
sw.Write("\r\n");
sw.Write("SOURCE: " + ex.Source);
sw.Write("\r\n");
sw.Write("FORM NAME: " + System.Web.HttpContext.Current.Request.Url.ToString());
sw.Write("\r\n");
sw.Write("QUERYSTRING: " + Request.QueryString.ToString());
sw.Write("\r\n");
sw.Write("TARGETSITE: " + ex.TargetSite.ToString());
sw.Write("\r\n");
sw.Write("STACKTRACE: " + ex.StackTrace + System.Diagnostics.EventLogEntryType.Error);
sw.Write("\r\n");
sw.WriteLine("-----------------------------------------------------------------------------------------");
sw.Close();
}

Hope this helps

Good Luck.

Categories: ASP.Net

Upload multiple files with ASP.Net 4.5

April 5, 2016 Leave a comment

Hi all,

Try this example to Upload multiple files with ASP.Net 4.5 in Visual Studio 2012 and Visual Studio 2013

ASPX Page :

<asp:FileUpload ID="FileUpload1" runat="server" AllowMultiple="true" />
<asp:Button ID="btnUpload" Text="Upload" runat="server" OnClick ="UploadMultipleFiles" accept ="image/gif, image/jpeg" />
<asp:Label ID="lblSuccess" runat="server" ForeColor ="Green" />

In Code behind :

protected void UploadMultipleFiles(object sender, EventArgs e)
{
foreach (HttpPostedFile postedFile in FileUpload1.PostedFiles)
{
string fileName = Path.GetFileName(postedFile.FileName);
postedFile.SaveAs(Server.MapPath("~/Uploads/") + fileName);
}
lblSuccess.Text = string.Format("{0} files have been uploaded successfully.", FileUpload1.PostedFiles.Count);
}

Hope this helps

Good Luck.

Categories: ASP.Net