472,373 Members | 2,079 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,373 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 6575
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: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
0
by: jack2019x | last post by:
hello, Is there code or static lib for hook swapchain present? I wanna hook dxgi swapchain present for dx11 and dx9.
0
DizelArs
by: DizelArs | last post by:
Hi all) Faced with a problem, element.click() event doesn't work in Safari browser. Tried various tricks like emulating touch event through a function: let clickEvent = new Event('click', {...

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.