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

Need help with using Classes 1

Status
Not open for further replies.

AgentM

MIS
Jun 6, 2001
387
US
I am trying to use the Class Class1 in a .Net page, but the error says that Class1 is not defined. Any help appreciated.
Here's the Code for the class:
Imports System
Imports System.Data
Imports System.Data.OleDb
Imports System.Collections

Namespace ClassNow
Public Class class1
Public Function GETData() As DataTable


Dim sConnStr As String = ConfigurationSettings.AppSettings("ConnectionString")
Dim objConn As New OleDbConnection(sConnStr)
objConn.Open()

Const strSQL As String = "SELECT ID FROM TBL_NAme"
Dim oledbAdapter1 As OleDbDataAdapter
oledbAdapter1 = New OleDbDataAdapter(strSQL, objConn)
Dim dsNew As New DataSet
oledbAdapter1.Fill(dsNew, "dsNew")

GETData = dsNew.Tables(0)

End Function
End Class
End Namespace


The code in the aspx page is:-

<% @ Import Namespace=&quot;System.Data&quot; %>
<% @ Import NameSpace=&quot;ClassNow&quot; %>

<html>

<script language=&quot;VB&quot; runat=&quot;server&quot;>
Sub Page_Load(sender as Object, e as EventArgs)
'Create a connection
If Not Page.IsPostBack then

dim newclass as new Class1

lstDepartments.DataSource = newClass.GetDAta
lstDepartments.DataBind()
lstDepartments.Items.Insert(0, new ListItem(&quot;-----Select Data----&quot;))

End if
End Sub

</Script>
 
Tried that no luck.

Is it something to do with the import stmt.
The Class file is in the same folder as the aspx page.

Thank you for your input.
 
The file has to get the assembly for the class somehow.

You can include the assembly from the .dll which if you have that ability it is the way to go.

My problem occured since i cannot upload a dll to my web server. Here is how to get around the dll:

use the Src attribute of page to load the applicable cs files. to load multiple files simply seperate them with a ';'

then import the applicable namespaces, and there ya go, no dll and still able to use OOP design. Ain't .net great :)

example code:

<%@ Page language=c# src=&quot;class1.cs;otherdir\class2.cs&quot; %>
<%@ Import Namespace=&quot;MyClass&quot; %>

<script language=c# runat=server>

public void test()
{
class1 temp = new class1();
class2 temp2 = new class2();
}

</script>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top