我有这个代码插入数据到数据库。我创建了一个<string, double, string[]>
的元组列表,并在嵌套的while循环中将元素添加到List中。下面是代码....循环执行与Tupled列表c#
System.IO.StreamReader file = new System.IO.StreamReader(@"C:\Users\Malik\Desktop\research_fields.txt");
Program p = new Program();
var dd = new List<Tuple<string, double, string>>();
//string document = "The trie data structure has many properties which make it especially attractive for representing large files of data. These properties include fast retrieval time, quick unsuccessful search determination, and finding the longest match to a given identifier. The main drawback is the space requirement. In this paper the concept of trie compaction is formalized. An exact algorithm for optimal trie compaction and three algorithms for approximate trie compaction are given, and an analysis of the three algorithms is done. The analysis indicate that for actual tries, reductions of around 70 percent in the space required by the uncompacted trie can be expected. The quality of the compaction is shown to be insensitive to the number of nodes, while a more relevant parameter is the alphabet size of the key.";
//string[] document = get_Abstract();
string line;
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 from sub_aminer_paper where pid between 1 and 500 and DATALENGTH(p_abstract) != 0";
SqlDataReader reader = query.ExecuteReader();
string summary = null;
while (reader.Read())
{
summary = reader["p_abstract"].ToString();
while ((line = file.ReadLine()) != null)
{
dd.Add(Tuple.Create(line, p.calculate_CS(line, summary), summary));
}
var top_value = dd.OrderByDescending(x => x.Item2).FirstOrDefault();
if (top_value != null)
{
// look up record using top_value.Item3, and then 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();
}
catch (Exception e)
{
Console.WriteLine("Exception: " + e.Message);
}
finally
{
Console.WriteLine("Executing finally block.");
}
我一直在使用C#在Visual Studio 2013调试它,我看到的是内里的声明while循环即dd.Add(Tuple.Create(line, p.calculate_CS(line, summary), summary));
只执行一次,而应该是执行22次如reader.Read()
有22个文件长度。 我已经检查了代码中只显示为//comment
的单个string document
,它工作正常,但不能从数据库中读取文档。 不明白为什么会这样。任何建议将不胜感激。
Beeecaaause ...'file.ReadLine ()'返回null? – Amit
你没有看到任何异常? – fred