string - while loop not working for tupled list c# db data update -


here code insertion method calling while iterating through while loop

program p = new program();             var lines = system.io.file.readlines(@"c:\users\malik\desktop\research_fields.txt");             var dd = new list<tuple<string, double, string>>(); try             {                 sqlconnection con = new sqlconnection("data source=khizer;initial catalog=subset_aminer;integrated security=true");                  con.open(); sqlcommand query = con.createcommand();                 query.commandtext = "select p_abstract sub_aminer_paper id between 1 , 500 , datalength(p_abstract) != 0";                  sqldatareader reader = query.executereader();                  string summary = null;                  while (reader.read())                 {                     summary = reader["p_abstract"].tostring();                     dd.addrange(lines.select(line => tuple.create(line, p.calculate_cs(line, summary), summary)));                      var top_value = dd.orderbydescending(x => x.item2).firstordefault();                      if (top_value != null && top_value.item2 > 0)                     {                         // record using top_value.item3, , store top_value.item1                         var abstrct = top_value.item3.tostring();                         var r_field = top_value.item1.tostring();                           write_to_database(abstrct, r_field);                         }                      }                     reader.close(); public static void write_to_database(string document, string research_field)         {             int result = 0;              try              {                  string connection = "data source=khizer;initial catalog=subset_aminer;integrated security=true;multipleactiveresultsets=true;";                   using (sqlconnection con = new sqlconnection(connection))                  {                      con.open();                       string query = "select id sub_aminer_paper pid between 1 , 500 , datalength(p_abstract) != 0 , p_abstract @p_abstract";                      using (sqlcommand cmd = new sqlcommand(query, con))                      {                          string st = document;                          cmd.parameters.addwithvalue("@p_abstract", st);                           int id = 0;                          using (sqldatareader reader = cmd.executereader())                          {                              while (reader.read())                              {                                  id = reader.getint32(0);                              }                               reader.close();                               string update_query = "update sub_aminer_paper set research_area = @research_area id = @id";                              using (sqlcommand cmd_update = new sqlcommand(update_query, con))                              {                                  int identity = id;                                  string r_field = research_field;                                   cmd_update.parameters.addwithvalue("@id", identity);                                  cmd_update.parameters.addwithvalue("@research_area", r_field);                                  //cmd_update.commandtimeout = 20;                                  result = cmd_update.executenonquery();                              }                          }                      }                      con.close();                  }                }              catch (exception e)              {                console.writeline("exception: " + e.message);              }                           {                console.writeline("executing block.");              }         } public double calculate_cs(string doc, string query)         {             var result = getcontent(doc, query);               var length = result.getlength(0);               double[] doc1array = new double[length];             double[] doc2array = new double[length];              //first doc             (int = 0; < length; i++)             {                 doc1array[i] = result[i, 0];             }              //second doc             (int = 0; < length; i++)             {                 doc2array[i] = result[i, 1];             }              var cossimilarity = calculatecosinesimilarity(doc1array, doc2array);               return cossimilarity;         } 

this appears fine issue updates every time value of variable string summary , uses updated value of summary in dd.addrange(lines.select(line => tuple.create(line, p.calculate_cs(line, summary), summary))); statement (i have checked while debugging) uses same value of summary after 3 or 4 iterations in statement var top_value = dd.orderbydescending(x => x.item2).firstordefault(); , causing no data update in database because of using same value of summary again n again. moreover, takes updated value of summary in 7th iteration , inserted data properly. after there same value taken var top_value = dd.orderbydescending(x => x.item2).firstordefault(); statement.

the results in database updated following. clear first 4 iterations worked iteration number 7 worked , no work or update @ , on.

id research_area
-------------------------
067 intrusion detection system
078 data stream management
092 data stream management
093 query processing
102 null
169 null
170 intrusion detection system
171 null
172 null
173 null
174 null
175 null
176 null

any , suggestions highly appreciated. thanks


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -