Hi , i am following a book to learn about data binding
i wrote this function dataload() in exam.vb.
now i want to call this function from web form, but its saying, " name data load not declared"
where is the problem ??
Thanks in advance
Imports Microsoft.VisualBasicImports System.DataModule exam Public Class exam Public Function DataLoad() As ICollection Dim dt As DataTable = New DataTable() Dim dv As DataView Dim dr As DataRow ' Add two columns to the DataTable dt.Columns.Add(New DataColumn( _ "ExamNumber", GetType(String))) dt.Columns.Add(New DataColumn( _ "ExamName", GetType(String))) ' Put some data in dr = dt.NewRow() dr(0) = "305" dr(1) = "Web Applications With VB.NET" dt.Rows.Add(dr) dr = dt.NewRow() dr(0) = "306" dr(1) = "Windows Applications With VB.NET" dt.Rows.Add(dr) dr = dt.NewRow() dr(0) = "310" dr(1) = "XML With VB.NET" dt.Rows.Add(dr) dr = dt.NewRow() dr(0) = "315" dr(1) = "Web Applications With Visual C# .NET" dt.Rows.Add(dr) dr = dt.NewRow() dr(0) = "316" dr(1) = _ "Windows Applications With Visual C# .NET" dt.Rows.Add(dr) dr = dt.NewRow() dr(0) = "320" dr(1) = "XML With Visual C# .NET" dt.Rows.Add(dr) ' And return the datatable ' wrapped in a dataview dv = New DataView(dt) Return dv End Function End ClassEnd Modulewebform :Partial Class thankyou Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load lbExams.DataSource = DataLoad() lbExams.DataTextField = "ExamName" DataBind() End SubEnd Class
hi thanks
I guessed i will have to call that function in webform
but problme is, how i will call ?? can you please write that code for me please ?
what code what i write in webform to call that dataload function from exam class to web form ?
the_bachelor
First do you need to have a Module? I've never seen one used in ASP.NET. I've seen them on Console Apps but...
Anyways, If I were you, i'd take Module exam and End Module out.
Then add the key word Shared to the definition of the function (Public Shared Dataload)
Then you'd be ready to do: lbExams.DataSource = exam.DataLoad()
fosiul01
ASKER
Omm problem is, i am following the code from book
MCAD/MCSD.NET Training Guide (Exam 70-305): Developing and Implementing Web Applications with Visual Basic .NET and Visual Studio® .NET
if i take your advise, then it would be like this is not it ?
Public Shared Function DataLoad() As ICollection
Dim dt As DataTable = New DataTable()
Dim dv As DataView
Dim dr As DataRow
........
........
dv = New DataView(dt)
Return dv
End Function
if this is right , still its same problem --1
But if i want to keep as author said, then what is the solution ?? -2
the_bachelor is right about the Module/End Module statements (I missed that).
Your web form is the "thankyou" class, and the DataLoad() function is in the "exam" class. Either the DataLoad() function needs to be in the same class as your web form, you need to create an instance of the "exam" class and call it's DataLoad() method, or declare the the DataLoad() as Shared (which makes more sense).
You can't call functions that belong to other classes without somehow referring to the class that contains them.
fosiul01
ASKER
problme is, how i will create instances ?? here is the problem.
Give me these solution :
1. i want to call dataload function from exam class to thankyou class, but how i will call ?? Please give me the code.( i realy dont know how to call)
2. I tried to make the function, shared, but still its same ,
the_bachelor
fosiul01,
I'm no author. I dont think tgerbert is either. But I'm studying for Exam 70-536 myself. And I ran inton my share of buggy stuff.
Authors are mere mortals like everybody. Sometimes they copy and paste the wrong stuff. Check out the documentation. I believe they provide you/us the readers with a website with corrected code.
you create an instance of the class exam by doing
Dim math_exam as exam = new exam
Then can do somthn like lbExams.DataSource = math_exam.DataLoad.
fosiul01
ASKER
HI the_bachelor ,
I understand i will have to write something like this in thankyou class
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim mydataload As myexam = New exam
' ????????????????????????????????????????????? how i will associated dataload function here ??
lbExams.DataSource = DataLoad()
lbExams.DataTextField = "ExamName"
DataBind()
End Sub
You will just have to show me , how i will call dataload here
I guessed i will have to call that function in webform
but problme is, how i will call ?? can you please write that code for me please ?
what code what i write in webform to call that dataload function from exam class to web form ?