Hundreds of times today, I learned about sqlconnection, sqlcommand, and SqlDataReader on MSDN to extract information obtained from the database.
The following code is part of the search () function that I am in charge:
1 string connectionString = GetConnectionString (); // SQL Server connection string 2 using (SqlConnection connection = new SqlConnection (connectionString) // instantiate the SQL connection Class 3 {4 connection. open (); // Open Database 5 List <string> tables = getTables (); 6 foreach (string table in tables) 7 {8 string strSQL = "SELECT * FROM" + table; // SQL statement to be executed 9 SqlCommand command = new SqlCommand (strSQL, connection ); // There are two parameters for the constructor of the Command object: SQL statements to be executed, and database connection objects. After creating the Command object, you can execute the SQL command. After execution, the data connection is completed and the 10 SqlDataReader reader = Command. ExecuteReader (); // Its return type is SqlDataReader. This method is used for user query operations. Use the Read (); method of the SqlDataReader object to Read data row by row. 11 try12 {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 else27 FMatch = descriptionMatch; 28 if (FMatch> 0) 29 {30 // related operation 31} 32} 33} 34 finally35 {36 // Always call Close when done reading.37 reader. close (); 38} 39} 40 connection. close (); // Close database 41}
This version is relatively large as the previous version. I did not store the data. Instead, I used Reader to match the data and keywords one by one (I feel like 2)
Low efficiency.
Since the database has not yet been fully determined, We tentatively set up a test to use the database for the relevant simulation test.
In the next few days, we will test the algorithm and optimize it.