Daily Report 2012.10.31 陈伯雄(step2)

今天上百度,MSDN上查阅学习了sqlconnection,sqlcommand,SqlDataReader等知识,用于提取从数据库获取的信息。

以下是我负责的search()函数的部分代码:

 1 string connectionString = GetConnectionString();                            //SQL Server链接字符串   
 2             using (SqlConnection connection = new SqlConnection(connectionString))      //SQL链接类的实例化
 3             {
 4                 connection.Open();                                                      //打开数据库
 5                 List<string> tables = getTables();
 6                 foreach(string table in tables)
 7                 {
 8                     string strSQL = "SELECT * FROM" + table;                            //要执行的SQL语句
 9                     SqlCommand command = new SqlCommand(strSQL, connection);            //Command对象的构造函数的参数有两个,一个是需要执行的SQL语句,另一个是数据库连接对象。创建Command对象后,就可以执行SQL命令,执行后完成并关闭数据连接
10                     SqlDataReader reader = command.ExecuteReader();                     //它的返回类型为SqlDataReader。此方法用于用户进行的查询操作。使用SqlDataReader对象的Read();方法进行逐行读取。
11                     try
12                     {
13                         while (reader.Read())
14                         {
15                             string title = reader["title"].ToString();
16                             int titleMatch = match(title);
17                             string keyword = reader["keyword"].ToString();
18                             int keywordMatch = match(keyword);
19                             string description = reader["description"].ToString();
20                             int descriptionMatch = match(description);
21                             int FMatch = -1;
22                             if (titleMatch > keywordMatch && titleMatch > descriptionMatch)
23                                 FMatch = titleMatch;
24                             else if (keywordMatch > descriptionMatch)
25                                 FMatch = keywordMatch;
26                             else
27                                 FMatch = descriptionMatch;
28                             if (FMatch > 0)
29                             {
30                                 //相关操作
31                             }
32                         }
33                     }
34                     finally
35                     {
36                         // Always call Close when done reading.
37                         reader.Close();
38                     }
39                 }
40                 connection.Close();  

  这个版本跟上一个版本查遍比较大,我并没有对数据进行储存,而是用Reader将数据与关键词逐条匹配(感觉很2)

,效率低下。

  由于数据库还未完全确定下来,我们暂定了一个测试用数据库进行相关模拟测试。

今后几天我们对其进行相关测试,并对算法进行优化。

 

posted @ 2012-10-31 23:19  DOOM_buaascse  阅读(262)  评论(0编辑  收藏  举报