473,387 Members | 1,575 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Instantiate objects

I have a dataset, datatable and data row which I have declared public in my
class. I instantiate them in one sub routine and go to use them again and I
get an 'Cannot find table 0' wrror

Public objds as new dataset()
Public objDataTable As new DataTable()
Public objRow As DataRow

Sub 1
Create dataset and use sucessfully
end sub

Sub 2
objds.tables(0).rows(0)(XMLItem("fieldname"))
End sub
Nov 19 '05 #1
6 1220
Chris,

does your dataset contain a table(0) in Sub1? And is sub2 called directly
after sub1 fires? Do you have a postback between accessing sub1 and sub2? If
so your variables are lost. If you want to prevent varibales between
postbacks you have to store them in viewstate, sessionstate or cache or
whatever fits your need.

Daniel
"Chris Kennedy" <ck**************@bleyonder.co.uk> schrieb im Newsbeitrag
news:eZ**************@tk2msftngp13.phx.gbl...
I have a dataset, datatable and data row which I have declared public in my
class. I instantiate them in one sub routine and go to use them again and
I
get an 'Cannot find table 0' wrror

Public objds as new dataset()
Public objDataTable As new DataTable()
Public objRow As DataRow

Sub 1
Create dataset and use sucessfully
end sub

Sub 2
objds.tables(0).rows(0)(XMLItem("fieldname"))
End sub

Nov 19 '05 #2
No there is no post back.

I have a create dataset function
Dim objConnection As New System.Data.SqlClient.SqlConnection(StrConnection)
objDataAdapter = New System.Data.SqlClient.SqlDataAdapter(StrSQL,
objConnection)
objBuilder = New SqlClient.SqlCommandBuilder(objDataAdapter)
objDataAdapter.UpdateCommand = objBuilder.GetUpdateCommand()
objDataAdapter.InsertCommand = objBuilder.GetInsertCommand()
objDataAdapter.DeleteCommand = objBuilder.GetDeleteCommand()
objDataAdapter.Fill(objDataSet,0)
return objDataSet

end function

I call it in a sub (called from the render controls in a custom control)

Dim objds as new Dataset()
objds = CreateDataSet(strConnection,strSQL)

In the render sub
I try

objds.tables(0).rows(0)(fieldname)

I get the error. The only way around it is to recreste the dataset. Anyideas
where I am going wrong.

"Daniel Walzenbach" <da***************@newsgroup.nospam> wrote in message
news:#q**************@TK2MSFTNGP10.phx.gbl...
Chris,

does your dataset contain a table(0) in Sub1? And is sub2 called directly
after sub1 fires? Do you have a postback between accessing sub1 and sub2? If so your variables are lost. If you want to prevent varibales between
postbacks you have to store them in viewstate, sessionstate or cache or
whatever fits your need.

Daniel
"Chris Kennedy" <ck**************@bleyonder.co.uk> schrieb im Newsbeitrag
news:eZ**************@tk2msftngp13.phx.gbl...
I have a dataset, datatable and data row which I have declared public in my class. I instantiate them in one sub routine and go to use them again and I
get an 'Cannot find table 0' wrror

Public objds as new dataset()
Public objDataTable As new DataTable()
Public objRow As DataRow

Sub 1
Create dataset and use sucessfully
end sub

Sub 2
objds.tables(0).rows(0)(XMLItem("fieldname"))
End sub


Nov 19 '05 #3
You'll want to post more code so we can see the problem. It sounds as
if you didn't add the DataTable object to the DataSet object's table
collection, but it's hard to tell without some code.

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Sun, 17 Jul 2005 02:01:55 -0700, "Chris Kennedy"
<ck**************@bleyonder.co.uk> wrote:
I have a dataset, datatable and data row which I have declared public in my
class. I instantiate them in one sub routine and go to use them again and I
get an 'Cannot find table 0' wrror

Public objds as new dataset()
Public objDataTable As new DataTable()
Public objRow As DataRow

Sub 1
Create dataset and use sucessfully
end sub

Sub 2
objds.tables(0).rows(0)(XMLItem("fieldname"))
End sub


Nov 19 '05 #4
Chris,

what error do you get? Place in a try...catch block and see what error you
get. It's usually gut to do sth. like the following if you access tables in
a dataset:

if myDataSet.Contains("myTable") then

' your code

end if

of course you should check if there are any rows in your datatable before
accessing them

if myDataSet.("myTable").rows.count>0 then

' your code

end if

and if your resultset is not predictable you can check if it contains
specific items as well

if myDataSet.("myTable").columns().contains("myItem") then

' your code

end if
But in your case it's important to first make sure if your dataset contains
a table with results. What you should do is to start sql profiler and check
the sql executed against your database. This will help you to understand
what happens behind the scenes and will help you to trace your problem

Daniel
"Chris Kennedy" <ck**************@bleyonder.co.uk> schrieb im Newsbeitrag
news:eS**************@tk2msftngp13.phx.gbl...
No there is no post back.

I have a create dataset function
Dim objConnection As New
System.Data.SqlClient.SqlConnection(StrConnection)
objDataAdapter = New System.Data.SqlClient.SqlDataAdapter(StrSQL,
objConnection)
objBuilder = New SqlClient.SqlCommandBuilder(objDataAdapter)
objDataAdapter.UpdateCommand = objBuilder.GetUpdateCommand()
objDataAdapter.InsertCommand = objBuilder.GetInsertCommand()
objDataAdapter.DeleteCommand = objBuilder.GetDeleteCommand()
objDataAdapter.Fill(objDataSet,0)
return objDataSet

end function

I call it in a sub (called from the render controls in a custom control)

Dim objds as new Dataset()
objds = CreateDataSet(strConnection,strSQL)

In the render sub
I try

objds.tables(0).rows(0)(fieldname)

I get the error. The only way around it is to recreste the dataset.
Anyideas
where I am going wrong.

"Daniel Walzenbach" <da***************@newsgroup.nospam> wrote in message
news:#q**************@TK2MSFTNGP10.phx.gbl...
Chris,

does your dataset contain a table(0) in Sub1? And is sub2 called directly
after sub1 fires? Do you have a postback between accessing sub1 and sub2?

If
so your variables are lost. If you want to prevent varibales between
postbacks you have to store them in viewstate, sessionstate or cache or
whatever fits your need.

Daniel
"Chris Kennedy" <ck**************@bleyonder.co.uk> schrieb im Newsbeitrag
news:eZ**************@tk2msftngp13.phx.gbl...
>I have a dataset, datatable and data row which I have declared public in my > class. I instantiate them in one sub routine and go to use them again and > I
> get an 'Cannot find table 0' wrror
>
> Public objds as new dataset()
> Public objDataTable As new DataTable()
> Public objRow As DataRow
>
> Sub 1
> Create dataset and use sucessfully
> end sub
>
> Sub 2
> objds.tables(0).rows(0)(XMLItem("fieldname"))
> End sub
>
>



Nov 19 '05 #5
If you declare a dataset

Public objds as new dataset()

as your dataset and then do:

dim objds as new dataset() within a sub does it lose it's public scope.
"Daniel Walzenbach" <da***************@newsgroup.nospam> wrote in message
news:O#**************@TK2MSFTNGP15.phx.gbl...
Chris,

what error do you get? Place in a try...catch block and see what error you
get. It's usually gut to do sth. like the following if you access tables in a dataset:

if myDataSet.Contains("myTable") then

' your code

end if

of course you should check if there are any rows in your datatable before
accessing them

if myDataSet.("myTable").rows.count>0 then

' your code

end if

and if your resultset is not predictable you can check if it contains
specific items as well

if myDataSet.("myTable").columns().contains("myItem") then

' your code

end if
But in your case it's important to first make sure if your dataset contains a table with results. What you should do is to start sql profiler and check the sql executed against your database. This will help you to understand
what happens behind the scenes and will help you to trace your problem

Daniel
"Chris Kennedy" <ck**************@bleyonder.co.uk> schrieb im Newsbeitrag
news:eS**************@tk2msftngp13.phx.gbl...
No there is no post back.

I have a create dataset function
Dim objConnection As New
System.Data.SqlClient.SqlConnection(StrConnection)
objDataAdapter = New System.Data.SqlClient.SqlDataAdapter(StrSQL,
objConnection)
objBuilder = New SqlClient.SqlCommandBuilder(objDataAdapter)
objDataAdapter.UpdateCommand = objBuilder.GetUpdateCommand()
objDataAdapter.InsertCommand = objBuilder.GetInsertCommand()
objDataAdapter.DeleteCommand = objBuilder.GetDeleteCommand()
objDataAdapter.Fill(objDataSet,0)
return objDataSet

end function

I call it in a sub (called from the render controls in a custom control)

Dim objds as new Dataset()
objds = CreateDataSet(strConnection,strSQL)

In the render sub
I try

objds.tables(0).rows(0)(fieldname)

I get the error. The only way around it is to recreste the dataset.
Anyideas
where I am going wrong.

"Daniel Walzenbach" <da***************@newsgroup.nospam> wrote in message news:#q**************@TK2MSFTNGP10.phx.gbl...
Chris,

does your dataset contain a table(0) in Sub1? And is sub2 called directly after sub1 fires? Do you have a postback between accessing sub1 and sub2?
If
so your variables are lost. If you want to prevent varibales between
postbacks you have to store them in viewstate, sessionstate or cache or
whatever fits your need.

Daniel
"Chris Kennedy" <ck**************@bleyonder.co.uk> schrieb im
Newsbeitrag news:eZ**************@tk2msftngp13.phx.gbl...
>I have a dataset, datatable and data row which I have declared public

in my
> class. I instantiate them in one sub routine and go to use them again

and
> I
> get an 'Cannot find table 0' wrror
>
> Public objds as new dataset()
> Public objDataTable As new DataTable()
> Public objRow As DataRow
>
> Sub 1
> Create dataset and use sucessfully
> end sub
>
> Sub 2
> objds.tables(0).rows(0)(XMLItem("fieldname"))
> End sub
>
>



Nov 19 '05 #6
If you declare it you don't need to instantiate it if this is what you do
later in a sub. But regarding your question, if you instantiate objds in a
sub (and it is declared on a page leveö) you can access it an any other sub
as long as there is no postback in between.

Daniel
"Chris Kennedy" <ck**************@bleyonder.co.uk> schrieb im Newsbeitrag
news:OG**************@TK2MSFTNGP14.phx.gbl...
If you declare a dataset

Public objds as new dataset()

as your dataset and then do:

dim objds as new dataset() within a sub does it lose it's public scope.
"Daniel Walzenbach" <da***************@newsgroup.nospam> wrote in message
news:O#**************@TK2MSFTNGP15.phx.gbl...
Chris,

what error do you get? Place in a try...catch block and see what error
you
get. It's usually gut to do sth. like the following if you access tables

in
a dataset:

if myDataSet.Contains("myTable") then

' your code

end if

of course you should check if there are any rows in your datatable before
accessing them

if myDataSet.("myTable").rows.count>0 then

' your code

end if

and if your resultset is not predictable you can check if it contains
specific items as well

if myDataSet.("myTable").columns().contains("myItem") then

' your code

end if
But in your case it's important to first make sure if your dataset

contains
a table with results. What you should do is to start sql profiler and

check
the sql executed against your database. This will help you to understand
what happens behind the scenes and will help you to trace your problem

Daniel
"Chris Kennedy" <ck**************@bleyonder.co.uk> schrieb im Newsbeitrag
news:eS**************@tk2msftngp13.phx.gbl...
> No there is no post back.
>
> I have a create dataset function
>
>
> Dim objConnection As New
> System.Data.SqlClient.SqlConnection(StrConnection)
> objDataAdapter = New System.Data.SqlClient.SqlDataAdapter(StrSQL,
> objConnection)
> objBuilder = New SqlClient.SqlCommandBuilder(objDataAdapter)
> objDataAdapter.UpdateCommand = objBuilder.GetUpdateCommand()
> objDataAdapter.InsertCommand = objBuilder.GetInsertCommand()
> objDataAdapter.DeleteCommand = objBuilder.GetDeleteCommand()
> objDataAdapter.Fill(objDataSet,0)
> return objDataSet
>
> end function
>
> I call it in a sub (called from the render controls in a custom
> control)
>
> Dim objds as new Dataset()
> objds = CreateDataSet(strConnection,strSQL)
>
> In the render sub
> I try
>
> objds.tables(0).rows(0)(fieldname)
>
> I get the error. The only way around it is to recreste the dataset.
> Anyideas
> where I am going wrong.
>
> "Daniel Walzenbach" <da***************@newsgroup.nospam> wrote in message > news:#q**************@TK2MSFTNGP10.phx.gbl...
>> Chris,
>>
>> does your dataset contain a table(0) in Sub1? And is sub2 called directly >> after sub1 fires? Do you have a postback between accessing sub1 and sub2? > If
>> so your variables are lost. If you want to prevent varibales between
>> postbacks you have to store them in viewstate, sessionstate or cache
>> or
>> whatever fits your need.
>>
>> Daniel
>>
>>
>> "Chris Kennedy" <ck**************@bleyonder.co.uk> schrieb im Newsbeitrag >> news:eZ**************@tk2msftngp13.phx.gbl...
>> >I have a dataset, datatable and data row which I have declared public in > my
>> > class. I instantiate them in one sub routine and go to use them
>> > again
> and
>> > I
>> > get an 'Cannot find table 0' wrror
>> >
>> > Public objds as new dataset()
>> > Public objDataTable As new DataTable()
>> > Public objRow As DataRow
>> >
>> > Sub 1
>> > Create dataset and use sucessfully
>> > end sub
>> >
>> > Sub 2
>> > objds.tables(0).rows(0)(XMLItem("fieldname"))
>> > End sub
>> >
>> >
>>
>>
>
>



Nov 19 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Felix Steffenhagen | last post by:
Hello @ all, i'm a newbie in python and have written a module for computations in a bayesian network. The module can be found at: http://www.informatik.uni-freiburg.de/~steffenh/bayes.py ...
5
by: Glenn Serpas | last post by:
I have Class A and Class B .. Class B has a private member that is a pointer to a Class A object. private: B *mypointer ; I instantiate the A object A* myobject new = A();
16
by: gabon | last post by:
Due a big project I would like to create different javascript classes and assign them to divs. But how? :) I know the usage of prototype but given that this could be possible: function...
9
by: the_grove_man | last post by:
I guess my question can go in two directions. I create applications that run multiple queries against a database. Generally speaking in the past I have used a Data Control (calling it dat1)...
0
by: jason | last post by:
i have classic ASP code that is calling a C# class library, which is wrapped for COM interop, and registered in the COM+ MMC. i have written 3 objects for the class library so far, and all three...
14
by: Ray5531 | last post by:
I have a console application in my local computer which I like to use remoting in it,to instanciate an object (MyClass.dll) in a web application(its bin folder) in a completely seperated box(in the...
7
by: J-T | last post by:
I can instantiate my object in my *ASP.NET* application in two ways: A) public sealed class RSSingleton { private static ReportingServiceProxy m_RsProxy=null; static RSSingleton() {...
1
by: Donald Westfield | last post by:
I have my own module, called mystuff.py, which is to be imported for an app. The number of classes in the module will vary, so I need a subroutine that will instantiate all of them as objects,...
4
by: Tomas | last post by:
A newbie question: How can I instantiate objects dynamically in VB.NET. E.g. I have the object 'Player' and I would like to instantiate it with the several instances (James, Gunner, etc.), without...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.