473,704 Members | 6,025 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Dynamically Create a Structure

I was wondering if it is possible to dynamically create a structure.

Something like this:

public sub main
sql = "Select Col1, Col2 from Table a"
dim al as new arraylist
al = LoadOracleData( sql)
'____Do amazing things

end sub

Private Function LoadOracleData( SQL as string) as arraylist
dim al as new arraylist

'...Parse out SQL Column names
'Use these names as the objects in the structure

'Structure Sample
'Dim Col1 as string
'Dim Col2 as string

'Load data into Structure sample and add to arraylist
'OLE/ODBC Connection
for...
al.add(sample structure)
Loop

return arraylist 'of structure
end function

I understand that datatypes should also be implimented...b ut for the
purposes of learning how to do this I have left it out....

-Peter

Nov 21 '05 #1
7 6785
pmclinn,
If you want to "dynamicall y" create a "structure" that contains SQL data I
would strongly suggest a DataSet & DataTable as they are "dynamic
structures" that contain data...
public sub main
sql = "Select Col1, Col2 from Table a"
dim table As DataTable
table = LoadOracleData( sql)
'____Do amazing things

end sub
Private Function LoadOracleData( SQL as string) as DataTable Dim table As New DataTable 'Structure Sample
'Dim Col1 as string
'Dim Col2 as string table.Columns.A dd("Col1", GetType(String) )
table.Columns.A dd("Col2", GetType(String) )

For a complete explanation of Datasets, DataTables, & DataAdapters along
with how to use them. I would strongly recommend you read David Sceppa's
book "Microsoft ADO.NET - Core Reference" from MS Press. As it is a good
tutorial on ADO.NET as well as a good desk reference once you know ADO.NET.

Hope this helps
Jay
"pmclinn" <pe***@mclinn.c om> wrote in message
news:11******** **************@ g14g2000cwa.goo glegroups.com.. .I was wondering if it is possible to dynamically create a structure.

Something like this:

public sub main
sql = "Select Col1, Col2 from Table a"
dim al as new arraylist
al = LoadOracleData( sql)
'____Do amazing things

end sub

Private Function LoadOracleData( SQL as string) as arraylist
dim al as new arraylist

'...Parse out SQL Column names
'Use these names as the objects in the structure

'Structure Sample
'Dim Col1 as string
'Dim Col2 as string

'Load data into Structure sample and add to arraylist
'OLE/ODBC Connection
for...
al.add(sample structure)
Loop

return arraylist 'of structure
end function

I understand that datatypes should also be implimented...b ut for the
purposes of learning how to do this I have left it out....

-Peter

Nov 21 '05 #2
Specifically I want to try to dynamically create a structure, or
class(.dll) in memory that I can refrence. I understand how the
datatables/rows... work but that is not what I'm looking for.... Thank
you though for your response.

Nov 21 '05 #3
pmclinn,
I suspected that you "think you want" to dynamically create a Class or
Structure. I was just testing the waters to see how persistent you are :-)

I have to ask, once you dynamically create the assembly, how are you going
to actually do "Do amazing things" in the code?

In order for your code to use the assembly you need to reference the
assembly where the type is, however if you dynamically create the assembly &
type you do not have the assembly to reference! The Seperated Interface
Pattern may be useful here.

http://martinfowler.com/eaaCatalog/s...Interface.html

I'm asking these questions not so much to scare you off, just to get you to
think about what you really getting into... ;-)

You can use either System.CodeDom or System.Reflecti on.Emit to dynamically
create an Assembly & Type. I would use CodeDom more for tools, where I
create the assembly once, then use it many times (many program executions).
I would use Reflection.Emit where I create the assembly & use it during the
execution of the program only... Of course I may also choose one over the
other if one provided easier then the other for the task at hand...

I have not looked deeply yet, but these article may be a good starting point
for Reflection.Emit & your task at hand:

http://www.codeproject.com/useritems/autocaster.asp

http://www.codeproject.com/useritems...dsafeforms.asp

Post if you need CodeDom samples.

However I am still recommending a DataTable over a dynamic assembly, as I
don't see anything in your "requiremen ts" that really warrents a dynamic
assembly... Hence the "think you want" comment above...

Hope this helps
Jay

"pmclinn" <pe***@mclinn.c om> wrote in message
news:11******** **************@ c13g2000cwb.goo glegroups.com.. .
Specifically I want to try to dynamically create a structure, or
class(.dll) in memory that I can refrence. I understand how the
datatables/rows... work but that is not what I'm looking for.... Thank
you though for your response.

Nov 21 '05 #4
It just seems like I should be able to write .net code and save it to a
string variable and then compile the class (Found in string). The
compile would only have to be done once before the data pull. It would
then save the new class to a local variable.

Nov 21 '05 #5
pmclinn,
It just seems like I should be able to write .net code and save it to a
string variable and then compile the class (Found in string). The I believe I stated both CodeDom & Reflection.Emit support creating &
compiling code dynamically.

My point is it a Chicken & Egg problem. How are you actually going to use
the dynamically created class?
It would
then save the new class to a local variable. You will actually wind up with a variable for the assembly itself, then a
variable for the Type (class or structure) itself, then a variable for an
instance of the type.

My point is to define the variable for an instance of the type may need to
be of type Object. IMHO variables of type Object "should" be avoided as
Strongly Typed classes & Early binding identify programs at compile time,
where as "As Object" tends to leave harder to find runtime problems. With
dynamically created code, the runtime problems may be even harder to find...

Using Early Binding (Option Strict On) you need a reference to the assembly
to get the Type, if the Type is dynamically created how are you going to
reference it. If you are using Late Binding, the Dataset is late bound so
"what's the point" of the dynamic class. It appears you want to create a
dynamically create a "data row", well .NET already does this. Its called
System.Data.Dat aRow.

Currently your "Requiremen ts" appear that you, yourself, want to implement
the Record Set pattern using Dynamically generated code.

http://www.martinfowler.com/eaaCatalog/recordSet.html

I'm suggesting rather then dynamically create types that implement the
Record Set pattern, simply use System.Data.Dat aSet as it already does the
implementation for you!
Don't get me wrong there are times when dynamically created types are very
useful, you may have requirements that are not reflected within this
thread... Hence my pointing you to the two places that are needed... I'm
considering Reflection.Emit to dynamically create assemblies from XML based
"control programs", in my case the dynamically created types would implement
one or more Seperated Interface Patterns to help ensure early binding...

Hope this helps
Jay
"pmclinn" <pe***@mclinn.c om> wrote in message
news:11******** **************@ o13g2000cwo.goo glegroups.com.. . It just seems like I should be able to write .net code and save it to a
string variable and then compile the class (Found in string). The
compile would only have to be done once before the data pull. It would
then save the new class to a local variable.

Nov 21 '05 #6
Jay,

The problem may be just the example I'm using here to understand a
programming concept. I'm just trying to see how to this coding works
in a simple to understand format. I chose an programming example that
I am familuar with just so I could get a grasp of a concept.

Pretend like all I want to know is how to create a virtual (Class)dll
and then refrence it from within a windows form application. Just make
the class and example very limitted so that I can catch on....

Something as simple as: 'Add a number to a total
Class Simple
private var as int
Get..

Set...
end class

;) Then, I'll ask for help on when to use it in the future...Trust me.

Nov 21 '05 #7
pmclinn,
Did you look at the two links I gave earlier?

Both included examples of what you are asking?

Hope this helps
Jay

"pmclinn" <pe***@mclinn.c om> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.com.. .
Jay,

The problem may be just the example I'm using here to understand a
programming concept. I'm just trying to see how to this coding works
in a simple to understand format. I chose an programming example that
I am familuar with just so I could get a grasp of a concept.

Pretend like all I want to know is how to create a virtual (Class)dll
and then refrence it from within a windows form application. Just make
the class and example very limitted so that I can catch on....

Something as simple as: 'Add a number to a total
Class Simple
private var as int
Get..

Set...
end class

;) Then, I'll ask for help on when to use it in the future...Trust me.

Nov 21 '05 #8

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

Similar topics

3
2569
by: Robert Oschler | last post by:
Hello, I am a Python newbie (by experience, not chronologically :) ), so if any of this doesn't make sense my apologies in advance. I am reading the chapter in The Python Cookbook on databases and the MySQLdb module. In it they show an example of a recipe that lets you access fields in a MySQL row by name rather than by column number. For example, given a MySQL row object from a fetchone() call:
1
2566
by: Vince C. | last post by:
Hi all, I've created XML documents that are described with a schema. I'm using those documents to create web pages. All my web pages contain a fixed header and a variable document part. The header is the same in each page and is described in an XML document, "Head.xml". The document part, which is variable in content, is described in other XML files (e.g. "Document.xml", "Product.xml", "Register.xml").
10
63600
by: Free-Ed, Ltd. | last post by:
I am going nuts trying to find a paragraph in a book that described how to change the text content (HTML) in a DIV. Actually I have an array of HTML strings that I want to drop into the DIV, depending on button clicks, etc. Putting this stuff into TEXTAREA and TEXT is simple, but I want to be able to mix font families, weights, sizes, and stuff like that. Thanks for your help.
5
2015
by: MarjaR | last post by:
For my application I need to develop an interface with an external organisation, based on XMLHTTP messaging. Depending on the specific purpose of the communication, this external organisation will send me various XML schemas (XSD documents) specifying the structure for the message interfaces. I need to be able to interpret these XSD documents and dynamically generate my database structure based on that. But... I don't have a clue...
3
2675
by: eSapient | last post by:
I created a web page which contains a form which contains a table. The number of rows for the table are determined dynamically. The first cell of each row contains a HyperLink control and the last cell contains a CheckBox control. In order for the ViewState mechanism to work correctly, I: 1. create the structure (add rows/columns) of the table in the OnInit handler when it is a PostBack, 2. create the table structure and populate its...
2
1636
by: grawsha2000 | last post by:
Hello, How can I add a table to asp.net page dynamically with Code Behind style. I still can't find a way of doing it. This really causes me a big problem when I deal with records from database as I need to construct the table dynamically.
11
3780
by: skumar434 | last post by:
Hi everybody, I am faceing problem while assigning the memory dynamically to a array of structures . Suppose I have a structure typedef struct hom_id{ int32_t nod_de; int32_t hom_id;
6
4832
by: AlabiChin | last post by:
Hello, I'm trying to find out if it is possible to dynamically add or remove fields for a structure. I'm in a situation where I don't know how many items I want to store and, therefore, will not know the size of the structure at compile time and would like to handle it at runtime (after having gathered necessary data). If this is not possible to do this using standard C++, do you know if it is in a Win32 API environment?
2
4363
by: djnokturnal | last post by:
Hey guys / gals, First time posting and of course I am sure it is something that has been answered 100 times but for some reason I just cant find the answer :) First off here is the structure of the xml: <Stats> <Structure> <Column DisplayName="GP" FieldName="GamesPlayed" Priority="1" /> <Column DisplayName="G" FieldName="Goals" Priority="2" />
0
8766
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8684
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9271
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9134
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8975
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7887
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5930
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4438
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3134
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.