473,386 Members | 1,705 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,386 software developers and data experts.

VB.Net - Creating Objects Question

Hello,

I need some clarification in creating objects. Consider the following
code... (note: The function InitializeListCombo initializes the combobox)

Private daLists As New OleDbDataAdapter

Private dsLists As New DataSet

Private dvLists As New DataView

msSQL = "SELECT * FROM Lists WHERE Active=True ORDER BY ListName,
ListItem"

'Create the DataAdapter for Categories Recordset

daLists = New OleDbDataAdapter(msSQL, cnADOConverse)

'Fill the Categories Recordset

daLists.Fill(dsLists, "Lists")

'Bind and Initialize cmbPreferredCurrency

dvLists = New DataView(dsLists.Tables("Lists"), "ListName =
'preferredcurrency'", "ListItem", DataViewRowState.CurrentRows)

InitializeListCombo(cmbPreferredCurrency, dvLists, "ListItem",
"ListItem")

'Bind and Initialize cmbHitCounterStyle

dvLists = New DataView(dsLists.Tables("Lists"), "ListName =
'hitcounterstyle'", "ListItem", DataViewRowState.CurrentRows)

InitializeListCombo(cmbHitCounterStyle, dvLists, "ListItem", "ListItem")

'Bind and Initialize cmbDuration

dvLists = New DataView(dsLists.Tables("Lists"), "ListName = 'duration'",
"ListItem", DataViewRowState.CurrentRows)

InitializeListCombo(cmbDuration, dvLists, "ListItem", "ListItem")

'Bind and Initialize cmbAutoRelists

dvLists = New DataView(dsLists.Tables("Lists"), "ListName =
'autorelists'", "ListItem", DataViewRowState.CurrentRows)

InitializeListCombo(cmbAutoRelists, dvLists, "ListItem", "ListItem")

daLists.Dispose()

daLists = Nothing

dsLists.Dispose()

dsLists = Nothing

dvLists.Dispose()

dvLists = Nothing

Did I just create ONE Dataview object named dvLists or did I create FOUR
DataView objects all named dvLists? I am very confused about the New
keyword. I declare dvLists New in the Private statement and then four other
times.

If anyone could make this clear I would really appreciate it. Also... can
anyone tell me if the above code is structured correctly or a better way to
write the code if it is not correct?

Thanks,

Richard

Nov 21 '05 #1
3 1574
Richard,

When you have a question with code, please paste it first in a notebook,
copy it back and paste it than in a message, otherwise it is almost
impossible without more work for the one who tries to help you, than for you
to get quick a good idea about your problem.

However comming to your question see it as this
dim a as new dataview(dt)
This create a new dataview object

dim b as dataview
b = a

Now are a and b referencing to the same object which was original a.

I hope this helps?

Cor
Nov 21 '05 #2
dvList is a DataView Type identifier, when you assign the reference to the
object, the old object referenced by dvList will be disposed of provided no
other reference points to it.

HTH
--
OHM ( Terry Burns ) * Use the following to email me *

Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray()
For i As Int32 = 0 To ch.Length - 1
ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1)
Next
Process.Start("mailto:" & New String(ch))
--
"Richard Thornley" <rh**@thorsoft.com> wrote in message
news:Oq**************@TK2MSFTNGP11.phx.gbl...
Hello,

I need some clarification in creating objects. Consider the following
code... (note: The function InitializeListCombo initializes the combobox)

Private daLists As New OleDbDataAdapter

Private dsLists As New DataSet

Private dvLists As New DataView

msSQL = "SELECT * FROM Lists WHERE Active=True ORDER BY ListName,
ListItem"

'Create the DataAdapter for Categories Recordset

daLists = New OleDbDataAdapter(msSQL, cnADOConverse)

'Fill the Categories Recordset

daLists.Fill(dsLists, "Lists")

'Bind and Initialize cmbPreferredCurrency

dvLists = New DataView(dsLists.Tables("Lists"), "ListName =
'preferredcurrency'", "ListItem", DataViewRowState.CurrentRows)

InitializeListCombo(cmbPreferredCurrency, dvLists, "ListItem",
"ListItem")

'Bind and Initialize cmbHitCounterStyle

dvLists = New DataView(dsLists.Tables("Lists"), "ListName =
'hitcounterstyle'", "ListItem", DataViewRowState.CurrentRows)

InitializeListCombo(cmbHitCounterStyle, dvLists, "ListItem",
"ListItem")

'Bind and Initialize cmbDuration

dvLists = New DataView(dsLists.Tables("Lists"), "ListName =
'duration'", "ListItem", DataViewRowState.CurrentRows)

InitializeListCombo(cmbDuration, dvLists, "ListItem", "ListItem")

'Bind and Initialize cmbAutoRelists

dvLists = New DataView(dsLists.Tables("Lists"), "ListName =
'autorelists'", "ListItem", DataViewRowState.CurrentRows)

InitializeListCombo(cmbAutoRelists, dvLists, "ListItem", "ListItem")

daLists.Dispose()

daLists = Nothing

dsLists.Dispose()

dsLists = Nothing

dvLists.Dispose()

dvLists = Nothing

Did I just create ONE Dataview object named dvLists or did I create FOUR
DataView objects all named dvLists? I am very confused about the New
keyword. I declare dvLists New in the Private statement and then four
other times.

If anyone could make this clear I would really appreciate it. Also... can
anyone tell me if the above code is structured correctly or a better way
to write the code if it is not correct?

Thanks,

Richard

Nov 21 '05 #3
hi Richard

You shouldn't be using the new keyword more that once with the same object
what the new words do is that it allocate memory with the specified type
size to the variable that it is used against . so what you are doing here
is allocating memory place for the dataview while using the same reference
of an old one . if the GC is clever enough it will collect the old memory
item ( that now has no reference , no variable is used to access that
memory ) , however , it is by no mean a good practice. My suggestion to you
is that you either use a different variable name for each view , or you
use the properties of the dataview object to set it new pointed data.
Hope this helps

Mohamed Mahfouz
MEA Developer Support Center
ITworx on behalf of Microsoft EMEA GTSC

Nov 21 '05 #4

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

Similar topics

1
by: SRam | last post by:
I am coding for a server. After server is reading a particluar port, How can I create handles for them and distinguish them individually #!/usr/local/bin/perl -w use strict; use IO::Socket;...
6
by: Dim St Thomas | last post by:
I am a developer working on a database client program. I am testing this program on a Windows XP machine (1.5 GHz AMD chip, 480 Mb RAM, 60 Gb disk) This machine has Oracle 9.2.0.1.0 and RedBrick...
9
by: Murat Ozgur | last post by:
Hello, I want to know about "creating new objects without assignment to a reference" like this : ... new Employee("John","Woo"); .... Is this a good programming practice ? How does...
5
by: | last post by:
Trying to learn about manipulating collections of objects, and populating these objects dynamically from datasources. Could someone post a code sample that shows the following: Instantiating a...
9
by: Brian | last post by:
I have a question that some may consider silly, but it has me a bit stuck and I would appreciate some help in understanding what is going on. For example, lets say that I have a class that...
9
by: Daz | last post by:
Hello people! (This post is best viewed using a monospace font). I need to create a class, which holds 4 elements: std::string ItemName int Calories int Weight int Density
3
by: lars.uffmann | last post by:
Hi everyone! I am debugging a big piece of code on the search for memory leaks, using g++ under suse 9.3. Since I'm trying to eliminate ALL memory leaks, I now stumbled upon a class foo that is...
6
by: RSH | last post by:
Hi, i have a situation where I need to dynamically create objects in a loop. My question surrounds intantiation naming in such a scenerio. Below is a snippet that is basically hardcoding each...
9
by: =?Utf-8?B?YmJn?= | last post by:
Hi all, I read somewhere "using kernel stuff in thread is not good.." if ManualResetEvent object is created in thread but not actually used, will it affect performance? Bob
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
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.