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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TypeName or class not defined?

Status
Not open for further replies.

TheCivic

Programmer
Feb 7, 2006
34
GB
Hi everyone,
I have made a shared public function within a class that returns a data table. When i set the selectmethod of an objectdatasource to a function, i get the error :

The type specified in the TypeName property of ObjectDataSource 'ProjectDataSource' could not be found.

Anyone know why this is?

Also i have created a function within the class that returns a string, and then i executed that via the page and wrote the contents out to the page (just for make sure it works), but then i get the message :

Name [CLASSNAME] is not declared.

Why is it saying my class name is not declared? If i then put this code as a function within the page, it works fine!! But i need it in a class, so i can use the objectdatasource!!!

Any help would be grateful. Cheers

 
How have you declared the instance of your class from the page? It may be easier to diagnose this problem if you past an example of your class and an example of your code from the page...


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
No problem, my datasource is as follows :

<asp:ObjectDataSource
ID="CompanyDataSource"
runat="server"
SelectMethod="GetCompanies"
TypeName="eContrack" />


My class function is :

Imports System.Web.HttpContext
Imports Microsoft.VisualBasic

Public Class eContrack

Public Shared Function GetCompanies() As Data.DataTable

Dim oConn As Data.SqlClient.SqlConnection
Dim oComm As Data.SqlClient.SqlCommand
Dim oDA As Data.SqlClient.SqlDataAdapter
Dim oDT As New Data.DataTable
Dim vSQL As String = "Select CompanyID, CompanyName From tblCompany "
Dim vWhere As String = eContrack.AllianceCode("ABMemberID")

oConn = New Data.SqlClient.SqlConnection(Current.Session.Item("SqlDsn").ToString)

oConn.Open()

Try

If vWhere <> "" Then

vWhere = " Where " & vWhere

End If

vSQL = vSQL & vWhere & " Order By CompanyName"

oComm = New Data.SqlClient.SqlCommand(vSQL, oConn)
oComm.CommandType = Data.CommandType.Text

oDA = New Data.SqlClient.SqlDataAdapter(oComm)

oDA.Fill(oDT)

oDA.Dispose()
oComm.Dispose()

Catch ex As Exception

me.response.write(ex.message.tostring)

Finally

If oConn.State <> Data.ConnectionState.Closed Then
oConn.Close()
End If

oConn.Dispose()

End Try

Return oDT

End Function
End Class

End Class
 
For your first problem, I'd guess that it can't find the class (i.e. it has no namespace and isn't sure where to look). Try following the example from here:


As for your second problem, how did you declare the instance of your class from the page?


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.
 
Thanks for the reply so shortly. I have copied and pasted the example code, and that says the same thing about the TypeName not being defined.

As for your question about declaring the instance on the page?? What do you mean by that?

Is this a bug in Visual Studio 2005? i have done it before on another project and it was fine.
 
No, this is not a bug in VS2005. I have just followed that article and it works fine.

As for your question about declaring the instance on the page?? What do you mean by that?
I mean how have you declared the variable with a type of the class that you want to use?


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
I still dont know what u mean about declaring the variable/class.

I am trying to set the datasource of the dropdownlist, and this datasource points at the function within my class.
 
Also, not sure if this has anything to do with it, but if i try to publish the site, i get an error saying App_Web_**** could not be found.
 
Well, to create an instance of a class, you have to do something like:
Code:
Dim myVariable as New myClass
You would then call your function like:
Code:
myVariable.MyFunction()



____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
ca8msm, as i said i am setting an objectdatasource, so none of that code is needed.

Anyway, i have fixed the problem. Basically, i had to mark the folder as an application within IIS. I didnt know if this had to be done or not, cos i am adding ASP.NET pages with some existing asp pages.

Does anyone know why i had to change the folder in IIS to an application?? Or has it got something to do with knowing where to load the classes etc from?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top