Internet is growing Every Seconds :: Industry is growing Every Year

Monday, March 01, 2004

ASP Function : nb_getMaxID

This Function is used to get the maximum id existing in the table.
It accepts 2 arguments, namely tbl_name and fld_name
TableName – Name of the Table.
FieldName – Name of the Id Field(Colum name)
It returns the Maximum Id as Integer.

ASP code

Set Con = Server.CreateObject("ADODB.Connection")
CON.ConnectionString ="Provider=SQLOLEDB.1;User
Id="NB_USERiD";password="NB_PASSWORD";Persist Security
Info=False;Initial Catalog=db_name;Data Source="sYSTEM NAME";"
Con.open
Public Function nb_getMaxID(TableName,FieldName)
set nb_rsmax = Server.CreateObject("ADODB.RecordSet")
sql = "select max("&FieldName&") as Cnt from "& TableName '& " where
"& WhereCLs
nb_rsmax.open sql,Con
if not nb_rsmax.eof then
MaxCnt = nb_rsmax("Cnt")
else
MaxCnt=0
end if
if trim(MaxCnt)="" or isEmpty(MaxCnt) or Isnull(MaxCnt)then maxCnt=0
nb_rsmax.close
set nb_rsmax=Nothing
nb_getMaxID=MaxCnt
End Function

Payroll_ID=nb_getMaxID("Tbl_Payroll_Head", "Payroll_ID")+1 ' This is employee id