Team work --- Step 2

Source: Internet
Author: User
Tags sql server connection string

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.

 

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.