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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. comparing two dataTables

comparing two dataTables

Scheduled Pinned Locked Moved C#
debugginghelpquestion
6 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.
  • T Offline
    T Offline
    Twyce
    wrote on last edited by
    #1

    I am trying to create a relation between two datatables.Here is the code i am using SqlConnection conDatabase = new SqlConnection(databaseConnectionString); SqlCommand cmdDatabase = new SqlCommand("SELECT * FROM StudentModule",conDatabase); SqlDataAdapter daDatabase = new SqlDataAdapter(cmdDatabase); //Get Columns for DataRelation DataColumn[] databaseColumns = new DataColumn[dsImport.Tables[0].Columns.Count]; for (int i = 0; i < databaseColumns.Length;i++) { databaseColumns[i] = dsImport.Tables[0].Columns[i]; } OleDbConnection conSpread = new OleDbConnection(spreadSheetConnectionString); OleDbCommand cmdSpread = new OleDbCommand("SELECT * FROM[Sheet1$]",conSpread); OleDbDataAdapter daSpread = new OleDbDataAdapter(cmdSpread); //Get Columns for DataRelation DataColumn[] spreadColumns = new DataColumn[dsImport.Tables[1].Columns.Count]; for (int i = 0; i < spreadColumns.Length;i++) { spreadColumns[i] = dsImport.Tables[1].Columns[i]; } //Create DataRelation DataRelation r = new DataRelation(string.Empty,databaseColumns, spreadColumns,false); dsImport.Relations.Add(r); The problem is that when i debug and step into the code the debugger does not go into the for loops,and therefore does not load the columns.What could be causing this plz help?

    S 1 Reply Last reply
    0
    • T Twyce

      I am trying to create a relation between two datatables.Here is the code i am using SqlConnection conDatabase = new SqlConnection(databaseConnectionString); SqlCommand cmdDatabase = new SqlCommand("SELECT * FROM StudentModule",conDatabase); SqlDataAdapter daDatabase = new SqlDataAdapter(cmdDatabase); //Get Columns for DataRelation DataColumn[] databaseColumns = new DataColumn[dsImport.Tables[0].Columns.Count]; for (int i = 0; i < databaseColumns.Length;i++) { databaseColumns[i] = dsImport.Tables[0].Columns[i]; } OleDbConnection conSpread = new OleDbConnection(spreadSheetConnectionString); OleDbCommand cmdSpread = new OleDbCommand("SELECT * FROM[Sheet1$]",conSpread); OleDbDataAdapter daSpread = new OleDbDataAdapter(cmdSpread); //Get Columns for DataRelation DataColumn[] spreadColumns = new DataColumn[dsImport.Tables[1].Columns.Count]; for (int i = 0; i < spreadColumns.Length;i++) { spreadColumns[i] = dsImport.Tables[1].Columns[i]; } //Create DataRelation DataRelation r = new DataRelation(string.Empty,databaseColumns, spreadColumns,false); dsImport.Relations.Add(r); The problem is that when i debug and step into the code the debugger does not go into the for loops,and therefore does not load the columns.What could be causing this plz help?

      S Offline
      S Offline
      Syed Mehroz Alam
      wrote on last edited by
      #2

      Looks you missed the statement to fill the DataSet.

      daDatabase.Fill(dsImport)

      Regards, Syed Mehroz Alam

      My Blog My Articles

      T 2 Replies Last reply
      0
      • S Syed Mehroz Alam

        Looks you missed the statement to fill the DataSet.

        daDatabase.Fill(dsImport)

        Regards, Syed Mehroz Alam

        My Blog My Articles

        T Offline
        T Offline
        Twyce
        wrote on last edited by
        #3

        Thank you very much.i did not see that

        1 Reply Last reply
        0
        • S Syed Mehroz Alam

          Looks you missed the statement to fill the DataSet.

          daDatabase.Fill(dsImport)

          Regards, Syed Mehroz Alam

          My Blog My Articles

          T Offline
          T Offline
          Twyce
          wrote on last edited by
          #4

          i filled the dataset but it is still doing the same thing. Anything else i'm missing???

          S 1 Reply Last reply
          0
          • T Twyce

            i filled the dataset but it is still doing the same thing. Anything else i'm missing???

            S Offline
            S Offline
            Syed Mehroz Alam
            wrote on last edited by
            #5

            It seems that you want to fill the same dataset in both the queries. Are you sure you are using the correct overload of Fill()[^] method.?

            My Blog My Articles

            T 1 Reply Last reply
            0
            • S Syed Mehroz Alam

              It seems that you want to fill the same dataset in both the queries. Are you sure you are using the correct overload of Fill()[^] method.?

              My Blog My Articles

              T Offline
              T Offline
              Twyce
              wrote on last edited by
              #6

              yes I want to Fill thesame dataset so that the comparison can be done and then create a third datatable

              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