473,785 Members | 2,858 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Deterimine columns of dataset from code - reflection?

Hi!

How do I explore in code, which properties (columns) are in a datatable? I
need to run some code for each column.

I guess the answer is reflection somehow, but I dont know where to start.

If someone could point me to a relevant example, I would be most grateful.
:)

Thanks in advance

- Klaus
Nov 21 '05 #1
24 1451
Hi Klaus...

Reflection isn't necessary in this case - the DataSet / DataTable /
DataColumn object model is sufficient...

Code:

For Each t As DataTable In Me.DataSet1.Tab les
MessageBox.Show (t.TableName)
For Each c As DataColumn In t.Columns
MessageBox.Show (c.ColumnName)
Next
Next

HTH

Nigel Armstrong

"Klaus Jensen" wrote:
Hi!

How do I explore in code, which properties (columns) are in a datatable? I
need to run some code for each column.

I guess the answer is reflection somehow, but I dont know where to start.

If someone could point me to a relevant example, I would be most grateful.
:)

Thanks in advance

- Klaus

Nov 21 '05 #2
Hi Klaus...

Reflection isn't necessary in this case - the DataSet / DataTable /
DataColumn object model is sufficient...

Code:

For Each t As DataTable In Me.DataSet1.Tab les
MessageBox.Show (t.TableName)
For Each c As DataColumn In t.Columns
MessageBox.Show (c.ColumnName)
Next
Next

HTH

Nigel Armstrong

"Klaus Jensen" wrote:
Hi!

How do I explore in code, which properties (columns) are in a datatable? I
need to run some code for each column.

I guess the answer is reflection somehow, but I dont know where to start.

If someone could point me to a relevant example, I would be most grateful.
:)

Thanks in advance

- Klaus

Nov 21 '05 #3
Klaus,

Why everybody wants the last times to do latebinding for things which are
free to get at design time, it seems for me if the word "reflection " has
something magical.

To get all columns from a datatable than this is enough

\\\
Public Module main
Public Sub main()
Dim dt As New DataTable
dt.Columns.Add( "Klaus")
dt.Columns.Add( "Cor")
For Each dc As DataColumn In dt.Columns
MessageBox.Show (dc.ColumnName)
Next
End Sub
End Module
///

I hope this helps?

Cor

"Klaus Jensen" <CurseThemNasty Spammers!>
Hi!

How do I explore in code, which properties (columns) are in a datatable? I
need to run some code for each column.

I guess the answer is reflection somehow, but I dont know where to start.

If someone could point me to a relevant example, I would be most grateful.
:)

Thanks in advance

- Klaus

Nov 21 '05 #4
Klaus,

Why everybody wants the last times to do latebinding for things which are
free to get at design time, it seems for me if the word "reflection " has
something magical.

To get all columns from a datatable than this is enough

\\\
Public Module main
Public Sub main()
Dim dt As New DataTable
dt.Columns.Add( "Klaus")
dt.Columns.Add( "Cor")
For Each dc As DataColumn In dt.Columns
MessageBox.Show (dc.ColumnName)
Next
End Sub
End Module
///

I hope this helps?

Cor

"Klaus Jensen" <CurseThemNasty Spammers!>
Hi!

How do I explore in code, which properties (columns) are in a datatable? I
need to run some code for each column.

I guess the answer is reflection somehow, but I dont know where to start.

If someone could point me to a relevant example, I would be most grateful.
:)

Thanks in advance

- Klaus

Nov 21 '05 #5
"Cor Ligthert" <no************ @planet.nl> wrote in message
news:%2******** **********@TK2M SFTNGP09.phx.gb l...
Why everybody wants the last times to do latebinding for things which are
free to get at design time, it seems for me if the word "reflection " has
something magical.


I should have explained what I wanted to do more specific...

I need to write a macro, which generates code based on the dataset. Ie I
need to mark the dataset (MyData.MyReall yStrongTypedDat aset) and then write
code, which examines the dataset columns, and then generates a template
class exposing each column as a property.

I hope this makes sense, if not, ask me to explain myself again. :)

- Klaus
Nov 21 '05 #6
"Cor Ligthert" <no************ @planet.nl> wrote in message
news:%2******** **********@TK2M SFTNGP09.phx.gb l...
Why everybody wants the last times to do latebinding for things which are
free to get at design time, it seems for me if the word "reflection " has
something magical.


I should have explained what I wanted to do more specific...

I need to write a macro, which generates code based on the dataset. Ie I
need to mark the dataset (MyData.MyReall yStrongTypedDat aset) and then write
code, which examines the dataset columns, and then generates a template
class exposing each column as a property.

I hope this makes sense, if not, ask me to explain myself again. :)

- Klaus
Nov 21 '05 #7
Klaus,

When you use the standard by VBNet generated strongly typed dataset, you can
forever reach the base dataclass from which it inherits.

However I cannot find for you how that is done in your
MyData.MyReally StrongTypedData set

In fact is Nigel showing to you when you have that base dataset, how you can
do it. I saw his sample after that I had sand mine.

Cor
Nov 21 '05 #8
Klaus,

When you use the standard by VBNet generated strongly typed dataset, you can
forever reach the base dataclass from which it inherits.

However I cannot find for you how that is done in your
MyData.MyReally StrongTypedData set

In fact is Nigel showing to you when you have that base dataset, how you can
do it. I saw his sample after that I had sand mine.

Cor
Nov 21 '05 #9
"Cor Ligthert" <no************ @planet.nl> wrote in message
news:eG******** ******@TK2MSFTN GP14.phx.gbl...
In fact is Nigel showing to you when you have that base dataset, how you
can do it. I saw his sample after that I had sand mine.


Maybe I am missing a point, but I still dont know how to come from the
string "Mydata.MyStron gtypedDataset" to an object of that type. When I have
the dataset as a correctly typed dataset, Nigels og your code is great for
displaying all columns... But the first part - I still dont know. :-S

- Klaus
Nov 21 '05 #10

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

Similar topics

3
2550
by: Diego TERCERO | last post by:
Hi... I'm working on a tool for editing text resources for a family of software product my company produces. These text resources are found in a SQL Server database, in a table called "Resource" with the following structure : Resource{,en,fr,es} Yes.. these are the only languages supported actually. A couple of rows in that table would look like this :
0
1724
by: Jason Coyne Gaijin42 | last post by:
I have seen several people looking for a way to access the Columns collection when using the AutoGenerate = true option. Some people have gotten so far as to find the private autoGenColumnsArray that has the information, but we as developers have no way to access this information. I have come up with a solution for the problem, (as I am sure many others have) using reflection. Here is some sample code that will print out the auto...
2
864
by: Jason Coyne Gaijin42 | last post by:
I have seen several people looking for a way to access the Columns collection when using the AutoGenerate = true option. Some people have gotten so far as to find the private autoGenColumnsArray that has the information, but we as developers have no way to access this information. I have come up with a solution for the problem, (as I am sure many others have) using reflection. Here is some sample code that will print out the auto...
0
780
by: Klaus Jensen | last post by:
Hi! How do I explore in code, which properties (columns) are in a datatable? I need to run some code for each column. I guess the answer is reflection somehow, but I dont know where to start. If someone could point me to a relevant example, I would be most grateful. :)
2
2231
by: Kjetil Klaussen | last post by:
Hi, I’m having some troubles trying to bind my dataset to a GridView control through an ObjectDataSource control. The binding works fine for regular columns in my dataset, but I can’t seem to get my expression columns to show up in my GridView. Anybody knows any neat tricks to make this work? Here’s a “step-by-step” to reproduce my worries: 1. Create a new “ASP.NET web site” project
3
7404
by: ASPnewb1 | last post by:
I am currently filling a dataTable then adding this table to a dataset, setting the dataset to the Gridview's datasource. If I set the Gridview to generate columns automatically it will fill the grid just fine, but I can't get the automated column (column index 1) to be set to readonly. (Column 0 is actually an automated column of edit buttons) here's my code: DataSet ds = new DataSet(); DataTable dt = new DataTable();...
0
9645
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, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
10324
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...
1
10090
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8971
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 projectplanning, coding, testing, and deploymentwithout 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
6739
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
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4050
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
2
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2879
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.