Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. .TableName, why use that?

.TableName, why use that?

Scheduled Pinned Locked Moved C#
question
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mprice214
    wrote on last edited by
    #1

    Hi all, I've been trying to determine a good reason why one would use .TableName when the name of the DataTable variable is required anyway and .TableName is optional. Seems that having spent 10 minutes googling, gave me good enough reason to post here what seems like should be an easy question to answer...... I'm assuming it is the same type of situation one would encounter using ProEngineer (CAD). One could name a part with its part name (which would be the file name) and also have an optional "common name". So you could have 012569.prt which has a common name of Bolt. However, in my opinion, have different nomenclature for the same item is usually a "state of confusion" waiting to happen. Thanks!

    P P 2 Replies Last reply
    0
    • M mprice214

      Hi all, I've been trying to determine a good reason why one would use .TableName when the name of the DataTable variable is required anyway and .TableName is optional. Seems that having spent 10 minutes googling, gave me good enough reason to post here what seems like should be an easy question to answer...... I'm assuming it is the same type of situation one would encounter using ProEngineer (CAD). One could name a part with its part name (which would be the file name) and also have an optional "common name". So you could have 012569.prt which has a common name of Bolt. However, in my opinion, have different nomenclature for the same item is usually a "state of confusion" waiting to happen. Thanks!

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      Remember that a DataTable was originally introduced as part of a DataSet, which allows a hierarchical linkage of tables (or you could just bundle several tables together in one if you liked). The TableName allows you to do things like search for the table in the DataSet.

      "WPF has many lovers. It's a veritable porn star!" - Josh Smith

      As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.

      My blog | My articles | MoXAML PowerToys | Onyx

      1 Reply Last reply
      0
      • M mprice214

        Hi all, I've been trying to determine a good reason why one would use .TableName when the name of the DataTable variable is required anyway and .TableName is optional. Seems that having spent 10 minutes googling, gave me good enough reason to post here what seems like should be an easy question to answer...... I'm assuming it is the same type of situation one would encounter using ProEngineer (CAD). One could name a part with its part name (which would be the file name) and also have an optional "common name". So you could have 012569.prt which has a common name of Bolt. However, in my opinion, have different nomenclature for the same item is usually a "state of confusion" waiting to happen. Thanks!

        P Offline
        P Offline
        PIEBALDconsult
        wrote on last edited by
        #3
        1. In case of a collection of them. 1) For when one is passed into a method. etc.
        M 1 Reply Last reply
        0
        • P PIEBALDconsult
          1. In case of a collection of them. 1) For when one is passed into a method. etc.
          M Offline
          M Offline
          mprice214
          wrote on last edited by
          #4

          You can't do that with the variable?

          P 1 Reply Last reply
          0
          • M mprice214

            You can't do that with the variable?

            P Offline
            P Offline
            PIEBALDconsult
            wrote on last edited by
            #5

            Try it.

            M 1 Reply Last reply
            0
            • P PIEBALDconsult

              Try it.

              M Offline
              M Offline
              mprice214
              wrote on last edited by
              #6

              PIEBALDconsult wrote:

              Try it.

              Yes, I knew this would be coming. One can certainly add a table to either a collection or use it in a method without having a formal name (but I don't think that is what you meant, is it)

              public class Tables
              {
              public DataTable tblTest1;
              public DataTable tblTest2;
              public DataSet dsTables;

                  public Tables()
                  {
                      dsTables = new DataSet();
                      tblTest1 = new DataTable();
                      tblTest2 = new DataTable();
                      dsTables.Tables.Add(tblTest1);
                      dsTables.Tables.Add(tblTest2);
                                  
                  }
              
                  public void ShowTables()
                  {
                      DataTableCollection tables = this.dsTables.Tables;
              
                      foreach (DataTable tbl in tables)
                          Console.WriteLine(tables.IndexOf(tbl).ToString());
                  }
              }
              
              public static class Program
              {
                  static int Main(string\[\] args)
                  {
                      Tables coll = new Tables();
              
                      coll.ShowTables();
                      Console.WriteLine();
                      Console.ReadLine();
                      return 0;
                  }
              }
              

              granted, having the foreach execute on

              Console.WriteLine(tbl.TableName);

              seems a bit more useful at first glance, so I guess I have my answer.........

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups