|
-
Feb 8th, 2010, 07:20 PM
#1
Thread Starter
New Member
reference to a non-shared member requries an object reference
Can someone tell me what is the matter with this code:
Code:
Public Sub showdataset()
For Each dt As DataTable In dsEvents.Tables
Response.Write("<table border='1'>" & vbCrLf)
For Each row As DataRow In Table.Rows
Response.Write("<tr>" & vbCrLf)
For Each dc As DataColumn In Table.Columns
Response.Write("<td>" & row(dc).ToString & "</td>" & vbCrLf)
Next
Response.Write("</tr>" & vbCrLf)
Next
Response.Write("</table>" & vbCrLf)
Next
End Sub
-
Feb 8th, 2010, 07:29 PM
#2
Re: reference to a non-shared member requries an object reference
Do you maybe want dt.Rows instead?
-
Feb 8th, 2010, 07:30 PM
#3
Hyperactive Member
Re: reference to a non-shared member requries an object reference
What error are you getting, and where? Give us a clue to go on, okay?
-
Feb 8th, 2010, 07:33 PM
#4
Thread Starter
New Member
Re: reference to a non-shared member requries an object reference
@minitech
Yes, when I changed Table.rows to dt.rows and Table.columns to dt.columns, the problem went away.
But a new problem shows up now.
Code:
Public Sub showdataset()
For Each dt As DataTable In dsEvents.Tables
Response.Write("<table border='1'>" & vbCrLf)
For Each row As DataRow In dt.Rows
Response.Write("<tr>" & vbCrLf)
For Each dc As DataColumn In dt.Columns
Response.Write("<td>" & row(dc).ToString & "</td>" & vbCrLf)
Next
Response.Write("</tr>" & vbCrLf)
Next
Response.Write("</table>" & vbCrLf)
Next
End Sub
I've tried passing the Dataset as a referenced argument to this Sub, but that was no help.
To be more specific, the exact error is:
System.NullReferenceException: Object reference not set to an instance of an object.
Last edited by taersious; Feb 8th, 2010 at 07:54 PM.
Reason: Problem not solved.
-
Feb 8th, 2010, 09:30 PM
#5
Re: reference to a non-shared member requries an object reference
Sounds like an object isn't initialized, more specifically whatever dsEvents is. (dataTable I'm assuming)
-
Feb 8th, 2010, 10:07 PM
#6
Re: reference to a non-shared member requries an object reference
 Originally Posted by taersious
@minitech
Yes, when I changed Table.rows to dt.rows and Table.columns to dt.columns, the problem went away.
But a new problem shows up now.
Code:
Public Sub showdataset()
For Each dt As DataTable In dsEvents.Tables
Response.Write("<table border='1'>" & vbCrLf)
For Each row As DataRow In dt.Rows
Response.Write("<tr>" & vbCrLf)
For Each dc As DataColumn In dt.Columns
Response.Write("<td>" & row(dc).ToString & "</td>" & vbCrLf)
Next
Response.Write("</tr>" & vbCrLf)
Next
Response.Write("</table>" & vbCrLf)
Next
End Sub
I've tried passing the Dataset as a referenced argument to this Sub, but that was no help.
To be more specific, the exact error is:
Assuming the underline (and red) dsEvents is where the error is that you're telling us is a null reference exception, it's say dsEvents is null (equal to 'Nothing') when it hits that line. You should probably initialize it (dsEvents = New DataSet) at some point before using it. You might also want to fill it before using it too.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|