Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Type 1

Status
Not open for further replies.

arpan

Programmer
Oct 16, 2002
336
IN
A SQL Server DB table named LMST has 2 fields - LCode (int) & LName (varchar(50)). Now suppose I have the following ASP code:

<%
Dim strSQL
strSQL=&quot;SELECT LCode,LName FROM LMST&quot;
Set objRS.Open=objConn.Execute(strSQL)

Dim strType1,strType2
strType1=objRS(&quot;LCode&quot;).Type
strType2=objRS(&quot;LName&quot;).Type
Response.Write(strType1 & &quot;, &quot;)
Response.Write(TypeName(strType1) & &quot;<br><br>&quot;)
Response.Write(strType2 & &quot;, &quot;)
Response.Write(TypeName(strType2) & &quot;<br><br>&quot;)
Response.Write(VarType(objRS(&quot;LCode&quot;)) & &quot;, &quot;)
Response.Write(TypeName(objRS(&quot;LCode&quot;)))
Response.Write(VarType(objRS(&quot;LName&quot;)) & &quot;, &quot;)
Response.Write(TypeName(objRS(&quot;LName&quot;)))
%>

The above code, when executed, produces the following result:

5, Long

202, Long

5, Field

8, Field

What does objRS(&quot;LCode&quot;).Type & objRS(&quot;LName&quot;) do? Don't they give the datatype of the fields? Why is strType1 & strType2 showing 5 & 202 respectively though the TypeName shows Long for both strType1 & strType2? Also when VarType(objRS(&quot;LCode&quot;)) is producing 5 (for vbDouble), why isn't TypeName(objRS(&quot;LCode&quot;) showing the datatype of the field LCode but instead showing 'Field'?

Thanks,

Arpan
 
1) strType1, TypeName(strType1)
Result
5, Long
Explanation
Since the variables declared in ASP are variants, the type of the variables changed according to the values substituted in the variable. The Value is 5 and so Long is the type

2) strType2, TypeName(strType2)
Result
202, Long
Explanation
Since the variables declared in ASP are variants, the type of the variables changed according to the values substituted in the variable. The Value is 202 and so Long is the type. If the value is some &quot;string&quot; then it will be string.. u can try this

3) VarType(objRS(&quot;LCode&quot;)), TypeName(objRS(&quot;LCode&quot;))
Result
5, Field
Explanation
When calling the vartype function directly substituting the value from field value it goes with Precisions.. that is y it is Double. The Typename of the OBjRS(&quot;LCode&quot;) is Field object from the Recordset object.

4) VarType(objRS(&quot;LName&quot;)), TypeName(objRS(&quot;LName&quot;))
Result
8, Field
Explanation
Working Perfect.. Values vartype is String and Type name is Field..
 
Hi Ganesh,

Thanks for your response. I couldn't exactly follow the reason which you have provided in 2. The datatype of LCode is int & that of LName is varchar(100). Assume that the 1st record in the table is 1 (LCode) & Mumbai (LName). You are saying that &quot;the type of the variables change according to the values substituted in the variable&quot; which is correct & I agree as well. Now since objRS(&quot;LName&quot;) is Mumbai, then shouldn't TypeName(objRS(&quot;LName&quot;)) show String instead of Long?

What does objRS(&quot;LCode&quot;).Type & objRS(&quot;LName&quot;).Type do? Don't they give the datatype of the fields LCode & LName?

Regards,

Arpan
 
Here is the explanation

Q1) Now since objRS(&quot;LName&quot;) is Mumbai, then shouldn't TypeName(objRS(&quot;LName&quot;)) show String instead of Long?
Yes it will be string.. but since strType2=objRS(&quot;LName&quot;).Type is given, the integer value of string is 202 that is what is printed...

Q2) What does objRS(&quot;LCode&quot;).Type & objRS(&quot;LName&quot;).Type do? Don't they give the datatype of the fields LCode & LName?
&quot;The Type property is an integer that specifies the property data type.&quot;. That is why it is saying values 5 for Integer and 202 for string..

Hope this helps..
 
Hi Ganesh,

OK......OK......now I understand. That's precisely the reason why TypeName(strType2) is Long since strType2 becomes 202 & thus it is evaluated as TypeName(202). Am I right?

Thanks once again for your help,

Regards,

Arpan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top