Click here to Skip to main content
13,301,664 members (64,867 online)
Click here to Skip to main content
Articles » Languages » C# » Reflection » Downloads


72 bookmarked
Posted 1 May 2006

Introduction to Creating Dynamic Types with Reflection.Emit: Part 2

, 1 May 2006
Part 2 of an introduction to creating dynamic types. This article shows how to actually generate the methods in a dynamic type and how to call them.
using System;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace EmitPerfTesting
	public partial class TestBed : Form
		public TestBed()

		public static void Main()
			Application.Run(new TestBed());

		private void button1_Click(object sender, EventArgs e)
			SqlConnection con = new SqlConnection("Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=Northwind;Data Source=Conwell");
			SqlDataAdapter adp = new SqlDataAdapter("select * from Customers", con);
			DataSet ds = new DataSet();

			DataTable dt = ds.Tables[0];

			//Moment of truth!
			IDataRowAdapter dra = DataRowAdapterFactory.CreateDataRowAdapter(dt);

			StringBuilder text = new StringBuilder();
			foreach (DataRow row in dt.Rows)
				text.Append(row[dra.GetOrdinal("CustomerID")].ToString()).Append(", ");
				text.Append(row[dra.GetOrdinal("CompanyName")].ToString()).Append(", ");
				text.Append(row[dra.GetOrdinal("ContactName")].ToString()).Append(", ");
				text.Append(row[dra.GetOrdinal("ContactTitle")].ToString()).Append(", ");
				text.Append(row[dra.GetOrdinal("Address")].ToString()).Append(", ");
				text.Append(row[dra.GetOrdinal("City")].ToString()).Append(", ");
				text.Append(row[dra.GetOrdinal("Region")].ToString()).Append(", ");
				text.Append(row[dra.GetOrdinal("PostalCode")].ToString()).Append(", ");
				text.Append(row[dra.GetOrdinal("Country")].ToString()).Append(", ");
				text.Append(row[dra.GetOrdinal("Phone")].ToString()).Append(", ");
				text.Append(row[dra.GetOrdinal("Fax")].ToString()).Append(", ");
			textBox1.Text = text.ToString();

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

United States United States
I have been a professional developer since 1996. My experience comes from many different industries; Data Mining Software, Consulting, E-Commerce, Wholesale Operations, Clinical Software, Insurance, Energy.

I started programming in the military, trying to find better ways to analyze database data, eventually automating my entire job. Later, in college, I automated my way out of another job. This gave me the great idea to switch majors to the only thing that seemed natural…Programming!

You may also be interested in...

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.171207.1 | Last Updated 1 May 2006
Article Copyright 2006 by jconwell
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid