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

Sunday, February 27, 2005

ASP Function : getmc_ColumnValue

Description

This method is used to get the specified column value
It accepts 5 arguments namely, TableName, FieldName, KeyName,
KeyValue and datatype
TableName – Name of the table
FieldName – Name of the Field
KeyName – Name of the Column Name used to filter the table.
Keyvalue – value used in the filter
KeyName should be Primary key.
Datatype – Datatype of the keyname.


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=hol_sinar;Data Source="sYSTEM NAME";"
Con.open
Public Function
getmc_ColumnValue(TableName,FieldName,KeyName,KeyValue,datatype)
Colvalue=""
set bn_rskey = Server.CreateObject("ADODB.RecordSet")
if datatype="I" then 'for integer keyfield
sql = "select "&FieldName&" as Colvalue from "&TableName& " WHERE
"&KeyName& "="&Keyvalue
else 'for character keyfield
sql = "select "&FieldName&" as Colvalue from "&TableName& " WHERE
"&KeyName& "='"&Keyvalue&"'"
end if
bn_rskey.open sql,Con
if not bn_rskey.eof then
ColValue = bn_rskey("Colvalue")
end if
bn_rskey.close
set bn_rskey=Nothing

getmc_ColumnValue=ColValue
End Function

getmc_ColumnValue("Tbl_user","usr_nme","usr_id",1,"I")
getmc_ColumnValue("Tbl_user","usr_nme","usr_nme","Raja","C")