giovaniluigi
Member
- Joined
- Jan 9, 2011
- Messages
- 16
- Programming Experience
- 5-10
I'm implementing in a class, methods to manage a simple database.
This class will perform all the tasks related with database and will return results in simple structures to the other classes.
Remark: My Class was designed to deal with a single Table at once, so it is using internal variables to store a single table.
There is one method to retrieve results from a table and it is:
I pass to this method the SQL condition or filter and the sort direction if I want the result sorted.
The result is an Array of DataRow type.
I could return a DataTable but it would be the same for my purpose.
Now when I use this code I do something like this:
After opening the tables and storing the results now I can use the results that are in memory like this:
With the code above I'm retrieving the value on line 0 columm "ColummName" from a DataRow object.
PROBLEM:
My Class was designed to deal with a single Table at once.
So to retrieve results I create a local array and then GetItems() from the table.
Like this: LocalArray = GetItems()
BUT
It doesn't work, because when I assign the result of the GetItems() to the local array I'm just dealing with references.
So when I open the Table2 the class overrides the arrays inside of it and store the data from Table2 now.
This way, the local array (Table1) where Table1 was supposed to be... is not valid anymore because even being a local array, it is just pointers to the content inside the class.
I need a solution to extract the results and store into a local Array.
The solution would be the method GetItems() return an object and not just references.
But everytime I think in create an object, I fall into the problem in how to pass the individual values to it and not the references.
For example, I've tried with lists, but I fell into the same problem.
Someone knows how can I return an Array "By Value" instead of returning just pointers ?
This class will perform all the tasks related with database and will return results in simple structures to the other classes.
Remark: My Class was designed to deal with a single Table at once, so it is using internal variables to store a single table.
There is one method to retrieve results from a table and it is:
VB.NET:
Public Function GetItems(Optional ByVal condition As String = "", Optional ByVal sort As String = "") As DataRow()
I pass to this method the SQL condition or filter and the sort direction if I want the result sorted.
The result is an Array of DataRow type.
I could return a DataTable but it would be the same for my purpose.
Now when I use this code I do something like this:
VB.NET:
Dim db as New ClassDataBase
Private Table1 As New List(Of Data.DataRow)
Private Table2 As New List(Of Data.DataRow)
db.OpenTable("Table1_Name")
Table1 = db.GetItems()
db.CloseTable()
db.OpenTable("Table2_Name")
Table2 = db.GetItems()
db.CloseTable()
After opening the tables and storing the results now I can use the results that are in memory like this:
VB.NET:
MessageBox(Table1(0).Item("ColummName").ToString)
With the code above I'm retrieving the value on line 0 columm "ColummName" from a DataRow object.
PROBLEM:
My Class was designed to deal with a single Table at once.
So to retrieve results I create a local array and then GetItems() from the table.
Like this: LocalArray = GetItems()
BUT
It doesn't work, because when I assign the result of the GetItems() to the local array I'm just dealing with references.
So when I open the Table2 the class overrides the arrays inside of it and store the data from Table2 now.
This way, the local array (Table1) where Table1 was supposed to be... is not valid anymore because even being a local array, it is just pointers to the content inside the class.
I need a solution to extract the results and store into a local Array.
The solution would be the method GetItems() return an object and not just references.
But everytime I think in create an object, I fall into the problem in how to pass the individual values to it and not the references.
For example, I've tried with lists, but I fell into the same problem.
Someone knows how can I return an Array "By Value" instead of returning just pointers ?