Click here to Skip to main content
15,881,413 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am using function in aspx page as below.

Aspx Code
----------
<td align="center" title="<%=RdrDesign(" designation=")%>"> <%= FindVal(RdrEmp("Emp_number"), RdrDesign("DesigCode"))%></td>



aspx.vb code
-------------
Private Function FindVal(ByVal ID, ByVal Desig)
        Dim Conn As System.Data.SqlClient.SqlConnection = New System.Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("MPP").ConnectionString)
        Dim Cmd As New System.Data.SqlClient.SqlCommand
        Dim RdrCatVal As System.Data.SqlClient.SqlDataReader
        Dim StrQry As String
        Dim CatVal As Integer
        StrQry = "Select isnull(" & Desig & ",'N') from csEmpCategory where emp_number ='" & ID & "' "
        Cmd.Connection = Conn
        Cmd.CommandText = StrQry
        RdrCatVal = Cmd.ExecuteReader
        If RdrCatVal.HasRows Then
            While RdrCatVal.Read
                CatVal = RdrCatVal(0)
            End While
            FindVal = CatVal
        End If
    End Function


i am getting the error in the function parameter.

Error is "function without an 'As' Clause. return type of object assumed

what is this error.

Regards,
Ganesh.S

[edit]Tags, code blocks, HTML Character encode - OriginalGriff[/edit]
Posted
Updated 5-Jul-11 22:20pm
v2

Your function should return a value, and you have not told the compiler what type of value (integer, string etc.) it is returning, so the compiler is assuming yoyuu will return an object.

Depending on the setting you have, this will be a warning or an error

to get rid of the warning, ad As xxx to your function

e,g,

Private Function FindVal(ByVal ID, ByVal Desig) As integer
 
Share this answer
 
Comments
gani7787 6-Jul-11 4:28am    
I have used the below function.

Private Function FindVal(ByVal ID As Integer, ByVal Desig As Integer)
Dim Conn As System.Data.SqlClient.SqlConnection = New System.Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("MPP").ConnectionString)
Dim Cmd As New System.Data.SqlClient.SqlCommand
Dim RdrCatVal As System.Data.SqlClient.SqlDataReader
Dim StrQry As String
Dim CatVal As Integer
StrQry = "Select isnull(" & Desig & ",'N') from csEmpCategory where emp_number ='" & ID & "' "
Cmd.Connection = Conn
Cmd.CommandText = StrQry
RdrCatVal = Cmd.ExecuteReader
If RdrCatVal.HasRows Then
While RdrCatVal.Read
CatVal = RdrCatVal(0)
End While
FindVal = CatVal
End If
End Function

But, still it says error "Function without as as clause. return type of object assumed"

pls. hekp.

Regards,
Ganesh.s
Abhinav S 6-Jul-11 4:30am    
Please have a look at _Maxxx's answer. My answer was wrong (based on your query) and I have removed it.
Tarun.K.S 6-Jul-11 4:32am    
You still haven't understood what Maxxx said. You have to add an "as" like this :
Private Function FindVal(ByVal ID As Integer, ByVal Desig As Integer) As Integer
Tarun.K.S 6-Jul-11 4:34am    
Good answer! 5+
IF you don't want to return a value then don't use a function visual basic uses sub for such a needs

VB
 Public sub findval(byval ID as integer)
 End sub
<\pre>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900