Saturday, May 25, 2019

Angular 7 CRUD with Asp.Net Core With Web API using EF

CRUD Operations - Insert, update, delete and retrieve are implemented in Asp.Net Core Web API with Angular 7. First of all we'll build a Web API project in Asp.Net Core with required methods at server side using Entity Framework Core and SQL Server DB. download https://goo.gl/3SvTLK Refrence from CodAffection. All credit goes to CodAffection . for MVC with Web API https://goo.gl/pj9Equ taken referenve from CodAffection

Thursday, June 25, 2015

Function RandomNumberForLogo1(intHighNumber,intLowNumber)
intHighNumber = intHighNumber
intLowNumber = intLowNumber
dim arrOfRandNo(4)
For i = 0 to 3
Randomize
intNumber = Int((intHighNumber - intLowNumber + 1) * Rnd + intLowNumber)
MyRandomNo = intNumber
For y = 0 To 3

If intNumber = arrOfRandNo(y) Then
intNumber = Int((intHighNumber - intLowNumber + 1) * Rnd + intLowNumber)
MyRandomNo = intNumber
End If
Next
arrOfRandNo(i) = intNumber
Next
RandomNumberForLogo1 = arrOfRandNo
End Function

Tuesday, January 6, 2015

Pagination in ASP | Using ASP Classic | ASP VB script

Pagination in ASP | Using ASP Classic | ASP VB script

<% 'declare var
Dim Currpage, pageLen, lastNumber, PageRem, PageTen
Dim connection, recordset, STRSql, sConnString, next10, prev10, P
Dim RSPrevPage, RSNextPage, start
'Get the current page the user is on, if it's the first time they
'visit and the variable 'PageNo' is empty, then 'CurrPage' gets set to 1
'Else the current page variable 'CurrPage' is set to the page number requested
If IsEmpty(Request.Querystring("PageNo")) then
CurrPage = 1
Else
CurrPage = Cint(Request.Querystring("PageNo"))
End If
'the two functions below return the next 10 and prev 10 page number
Function getNext10(num)
pageLen = len(num)
If pageLen = 1 Then
next10 = 10
Else If pageLen>1 Then
pageRem = 10
pageTen = right(num, 1)
next10 = num + pageRem - pageTen
End If
End If
getNext10 = next10
End Function
Function getPrev10(num)
pageLen = len(num)
If pageLen = 1 then
prev10 = 1
Else If pageLen>1 then
lastNumber = right(num, 1)
prev10 = num - lastNumber - 10
End If
If prev10 = 0 then
prev10 = 1
End If
End If
getPrev10 = prev10
End Function
'create an instance of the ADO connection and recordset object
Set Recordset = Server.CreateObject("ADODB.Recordset")
'define the connection string
sConnString = Application("DSN")
'define our SQL variable
STRSql="SELECT * FROM tablename"
'Next set the location of the recordset
Recordset.CursorLocation = 3
'Execute the SQL and return our recordset
Recordset.open STRSql, sConnString
' pagesize is used to set the number of records that will be
' displayed on each page. For our purposes 10 records is what we want.
Recordset.PageSize = 10
'get the next 10 and prev 10 page number
next10 = getNext10(CurrPage)
prev10 = getPrev10(CurrPage)
'If there are no records
If Recordset.EOF Then
Response.write "No records to display"
Else
'this moves the record pointer to the first record of the current page
Recordset.AbsolutePage = CurrPage
'the below loop will loop until all the records of the current page have been
'displayed or it has reached the end of the recordset
Do Until Recordset.AbsolutePage <> CurrPage OR Recordset.Eof
'you can change these according to your database and table fields
response.write "ID: " & Recordset ("ID") & "
"
response.write "name: " & Recordset ("name") & "
"
response.write "Address: " & Recordset ("address") & "

"
Recordset.MoveNext
Loop
End If
'the next 2 lines setup the page number for the "previous" and "next" links
RSPrevPage = CurrPage -1
RSNextPage = CurrPage + 1
'find out the number of pages returned in the recordset
'if the Next10 page number is greater than the recordset page count
'then set Next10 to the recordset pagecount
If Next10 > Recordset.PageCount Then
Next10 = Recordset.PageCount
End If
'the variable start determines where to start the page number navigation
' i.e. 1, 10, 20, 30 and so on.
If prev10 = 1 AND next10 - 1 < 10 Then
start = 1
Else
start = Next10 - 10
If right(start, 1) > 0 Then
start = replace(start, right(start, 1), "0")
start = start + 10
End If
End If
'This checks to make sure that there is more than one page of results
If Recordset.PageCount > 1 Then
'Work out whether to show the Previous 10 '<<'
If currpage > 1 Then
response.write("<< ")
End If
'Work out whether to show the Previous link '<'
If NOT RSPrevPage = 0 then
response.write("< ")
End If
'Loop through the page number navigation using P as our loopcounter variable
For P = start to Next10
If NOT P = CurrPage then
response.write("" & P & " ")
Else
'Don't hyperlink the current page number
response.write(" " & P & " ")
End If
Next
'this does the same as the "previous" link, but for the "next" link
If NOT RSNextPage > Recordset.PageCount Then
response.write("> ")
End If
'Work out whether to show the Next 10 '>>'
If NOT Next10 = Recordset.PageCount Then
response.write(" >>")
End If
End If
%>

Monday, December 1, 2014

Calculate age Using Sql server script Calculate age Using Sql server script 2008, 2005

Calculate age Using Sql server

create function CalcAge (@dob datetime)
returns varchar(64)
as
begin
declare @age int
declare @getdate datetime = getdate()
if @dob >= @getdate
return 'Invalid input Parameter'
set @age = datediff(yy, @dob, @getdate)
if month(@dob) > month(@getdate) or
(month(@dob) = month(@getdate) and
day(@dob) > day(@getdate))
set @age = @age - 1
return convert(varchar,@age) + ' Years and ' + convert(varchar,datediff(dd,dateadd(yy,@age,@dob),@getdate)) + ' Days'
end

Tuesday, November 25, 2014

Enabling Unobtrusive Validation Mode in ASP.NET

Microsoft Visual Studio 2013 provides new Validation features which is include Unobtrusive Validation. Whenever you need to work with such type of Validation mode you will have to firstly configure your Web Application.

How to configure your Web.Config File

< configuration >
< appSettings >
< add key="ValidationSettings:UnobtrusiveValidationMode" value="None" >
< /appSettings >
< system.web >
< compilation debug="true" targetFramework="4.5" />
< httpRuntime targetFramework="4.5" />
< /system.web >
< /configuration >



How to configure your .aspx File

< asp:TextBox runat="server" ID="txt" />
< asp:RequiredFieldValidator ID="RequiredFieldValidator1" ErrorMessage="txt is required" ControlToValidate="txt" runat="server" Text="Text is Required" Display="Dynamic" />
< asp:Button ID="Button1" Text="Submit" runat="server" />

Thursday, October 30, 2014

how to read all filename from folder using ASP Vbscript

Read all filenames from folder using ASP Classic Vbscript

Sometimes you require to get a list of all the files name from a folder, I was thinking how it can be implemented, the solution is to used the interface and write a script in VBScript. There is a sample script which is build in ASP Vbscript will get the list of files on a Folder.

function GetFiles(pFolder, pPattern)
dim Filelist
set Filelist = Server.CreateObject("SCRIPTING.DICTIONARY")
dim Regex
set Regex = new RegExp
Regex.IgnoreCase = true
Regex.Pattern = pPattern
dim Fso
set Fso = Server.CreateObject("SCRIPTING.FILESYSTEMOBJECT")
dim Folder
set Folder = Fso.GetFolder(Server.MapPath(pFolder))
dim File
for each File in Folder.Files
if Regex.Test(File.Name) then
Filelist.add File.Name, Array(File.Type, File.Size, File.DateLastModified)
end if
next
set File = nothing
set Folder = nothing
set Fso = nothing
set Regex = nothing
set GetFiles = Filelist
end function
dim Files
set Files = GetFiles("agencies", "\.(asp|gif|jpg|jpeg|png|tif)$")
if Files.Count = 0 then
Response.write "There are no images to display. "
end if
dim Filename
for each Filename in Files
Response.write Filename
Response.write Files(Filename)(0)
Response.write Files(Filename)(1)
Response.writeFiles(Filename)(2)
next
How To Generate Random String Using ASP Classic vb script, Sql

Generate Random String Using ASP Classic VB script, Sql

Simple and highly customizable function so that you can generate random strings using VBScript that you can use in your ASP/VBScript applications. The random strings can be used for various purposes: Referral Codes, Promotional Codes, Random password for new registrations

function GetRefID(Val)
tot_unique=8
rid = ""
redim random_letter(tot_unique)
randomize
For counter = 1 to tot_unique
random_number = Int(26 * Rnd + 97)
random_letter(counter) = Chr(random_number)
'response.write random_letter(counter)
for check=1 to counter-1
if random_letter(check)= random_letter(counter) then
counter=counter-1
end if
next
next
For counter = 1 to tot_unique
'response.write "
  • " & random_letter(counter) & "
  • "
    rid=rid & random_letter(counter)
    next
    Userid= Val & rid
    Sql="Select id from tbl Where id ='"&Userid&"' "
    Set Rs = objcon.execute(Sql)
    IF Not Rs.eof then
    GetRefID()
    Else
    GetRefID= Userid
    End IF
    Rs.close()
    Set Rs = Nothing
    End Function