How do I decalre a new DataTable whose name is based on a string value

Posted on 2006-03-21
Last Modified: 2010-04-16
I had a string called zDefinedType, I want my DataTable to be able to dynamically name itself after the string.


string zDefinedType = "Generic";
DataTable textValueOf(zDefinedType) = New DataTable();

Any Ideas?
Question by:tatton777
    LVL 10

    Assisted Solution

    I doubt that is possible. You could create a new table and add that to hashtable with zDefineType as a key and then you could access that table with that name. I'm not sure what exactly are you trying to do. If you could provide more info on what you are trying to achieve then I could help more.

    LVL 12

    Accepted Solution

    Does this not work?
          string strTableName = "test";
          DataTable myTable = new DataTable(strTableName);
          Console.WriteLine("table Name: {0}", myTable.TableName);

    LVL 12

    Expert Comment

    Up to tatton777 really; I think both athapa and myself offer solutions, though we both needed more info if they weren't sufficient.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
    This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now