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

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...but for the
purposes of learning how to do this I have left it out....

-Peter

Nov 21 '05 #1
7 6727
pmclinn,
If you want to "dynamically" 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.Add("Col1", GetType(String))
table.Columns.Add("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.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.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...but 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.Reflection.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 "requirements" that really warrents a dynamic
assembly... Hence the "think you want" comment above...

Hope this helps
Jay

"pmclinn" <pe***@mclinn.com> wrote in message
news:11**********************@c13g2000cwb.googlegr oups.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.DataRow.

Currently your "Requirements" 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.DataSet 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.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.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.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.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
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...
1
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...
10
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,...
5
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...
3
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...
2
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...
11
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
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...
2
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...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

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.