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. List classList = new List();

List classList = new List();

Scheduled Pinned Locked Moved C#
databasecssdata-structuresquestion
5 Posts 2 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.
  • S Offline
    S Offline
    sharp source
    wrote on last edited by
    #1

    Hey guys, I'm trying to check the uniqueness of the index key of visual foxpro tables. From the tableinfo table I read all names of the tables in the database and the name of their index key. The name, index key and path (omniwinroot) are stored in an instance of class ActiveTable named tableToAnalyze Next I invoke a member method of ActiveTable (Analyze.Table) on that instance. This executes 2 queries on the table. The first one counts all the records, last one counts only those with distinct index key. If there are less unique index keys then there are rows in the table then the UNunique index keys are safed in a queue (so it could be fixed later). The goal is to copy (by value) tableToAnalyze to a list of instances of ActiveTable when double index keys were found. So something like this: Class classVar = new Class(); list classList= new List(); classVar.integer1 = 1; classVar.integer2 = 3; if (condition) classList.Add(classVar); From there i could display in a datagridview and prompt the user to repair (only those tables he wants to repair). The code I have seems to copy by reference. After all the tables are analyzed my list holds 2 (which is correct) of the same values. Both hold the values of the last table What am i doing wrong? private void dubbelNummeringToolStripMenuItem_Click(object sender, EventArgs e) { string sqlQueryTableInfo ="SELECT ctableid, flocation, ctablename, caliasname, cidfield, cidindex, cdatabase FROM tableinfo WHERE (cdatabase = 'dpatient') AND (flocation = 'data') AND (cidfield <> '') ORDER BY ctablename"; string connectionStringTableInfo = "Provider=VFPOLEDB.1;" + "Data Source=" + omniwinRoot + "\\tableinfo.dbf"; OleDbCommand commandTableInfo = new OleDbCommand(sqlQueryTableInfo); ActiveTable tableToAnalyze = new ActiveTable(); List tableToAnalyzeList = new List(); using (OleDbConnection ConnTableInfo = new OleDbConnection(connectionStringTableInfo)) { try { ConnTableInfo.Open(); commandTableInfo.Connection = ConnTableInfo; OleDbDataReader readerTableInfo = commandTableInfo.ExecuteReader(CommandBehavior.CloseConnection); while (readerTableInfo.Read()) { tableToAnalyze.omniwinRoot = omniwinRoot;

    P 1 Reply Last reply
    0
    • S sharp source

      Hey guys, I'm trying to check the uniqueness of the index key of visual foxpro tables. From the tableinfo table I read all names of the tables in the database and the name of their index key. The name, index key and path (omniwinroot) are stored in an instance of class ActiveTable named tableToAnalyze Next I invoke a member method of ActiveTable (Analyze.Table) on that instance. This executes 2 queries on the table. The first one counts all the records, last one counts only those with distinct index key. If there are less unique index keys then there are rows in the table then the UNunique index keys are safed in a queue (so it could be fixed later). The goal is to copy (by value) tableToAnalyze to a list of instances of ActiveTable when double index keys were found. So something like this: Class classVar = new Class(); list classList= new List(); classVar.integer1 = 1; classVar.integer2 = 3; if (condition) classList.Add(classVar); From there i could display in a datagridview and prompt the user to repair (only those tables he wants to repair). The code I have seems to copy by reference. After all the tables are analyzed my list holds 2 (which is correct) of the same values. Both hold the values of the last table What am i doing wrong? private void dubbelNummeringToolStripMenuItem_Click(object sender, EventArgs e) { string sqlQueryTableInfo ="SELECT ctableid, flocation, ctablename, caliasname, cidfield, cidindex, cdatabase FROM tableinfo WHERE (cdatabase = 'dpatient') AND (flocation = 'data') AND (cidfield <> '') ORDER BY ctablename"; string connectionStringTableInfo = "Provider=VFPOLEDB.1;" + "Data Source=" + omniwinRoot + "\\tableinfo.dbf"; OleDbCommand commandTableInfo = new OleDbCommand(sqlQueryTableInfo); ActiveTable tableToAnalyze = new ActiveTable(); List tableToAnalyzeList = new List(); using (OleDbConnection ConnTableInfo = new OleDbConnection(connectionStringTableInfo)) { try { ConnTableInfo.Open(); commandTableInfo.Connection = ConnTableInfo; OleDbDataReader readerTableInfo = commandTableInfo.ExecuteReader(CommandBehavior.CloseConnection); while (readerTableInfo.Read()) { tableToAnalyze.omniwinRoot = omniwinRoot;

      P Offline
      P Offline
      Pascal 0
      wrote on last edited by
      #2

      Creating a new instance of the ActiveTable variable should do the trick into your while loop while (readerTableInfo.Read()) { tableToAnalyze = new AnalyzeTable(); tableToAnalyze.omniwinRoot = omniwinRoot; tableToAnalyze.table = readerTableInfo.GetString(3).Trim(); tableToAnalyze.tableKey = readerTableInfo.GetString(4).Trim(); tableToAnalyze.AnalyzeTable(); tableToAnalyze.verschil = tableToAnalyze.tableRecords - tableToAnalyze.tableUniqueRecords; if (tableToAnalyze.verschil > 0) { tableToAnalyzeList.Add(tableToAnalyze); } }

      S 1 Reply Last reply
      0
      • P Pascal 0

        Creating a new instance of the ActiveTable variable should do the trick into your while loop while (readerTableInfo.Read()) { tableToAnalyze = new AnalyzeTable(); tableToAnalyze.omniwinRoot = omniwinRoot; tableToAnalyze.table = readerTableInfo.GetString(3).Trim(); tableToAnalyze.tableKey = readerTableInfo.GetString(4).Trim(); tableToAnalyze.AnalyzeTable(); tableToAnalyze.verschil = tableToAnalyze.tableRecords - tableToAnalyze.tableUniqueRecords; if (tableToAnalyze.verschil > 0) { tableToAnalyzeList.Add(tableToAnalyze); } }

        S Offline
        S Offline
        sharp source
        wrote on last edited by
        #3

        That did the trick indeed. I thought about it but couldn't understand why this would help. Still don't, hoping to come across an answer in the coming days. (studying c# for work) Anyway, thanks a lot.

        P 1 Reply Last reply
        0
        • S sharp source

          That did the trick indeed. I thought about it but couldn't understand why this would help. Still don't, hoping to come across an answer in the coming days. (studying c# for work) Anyway, thanks a lot.

          P Offline
          P Offline
          Pascal 0
          wrote on last edited by
          #4

          Because you were reassigning the properties of the same instance each time. Thats why you got the same object twice in your list because the object is by reference. With the modification, you'll create a new instance of the object on each iteration and each object in your list will be different because they point at their own reference. Hope that help :)

          S 1 Reply Last reply
          0
          • P Pascal 0

            Because you were reassigning the properties of the same instance each time. Thats why you got the same object twice in your list because the object is by reference. With the modification, you'll create a new instance of the object on each iteration and each object in your list will be different because they point at their own reference. Hope that help :)

            S Offline
            S Offline
            sharp source
            wrote on last edited by
            #5

            Yes, that helped ;) thanks

            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