Today, our team DOOM allocates work, and our team is responsible for the search of this site and Upload/Download content modules in the Online System.
My task is the search function in the search of this site. The function is to find data that matches the user's search Content from the database in the Content Pipeline group, and pass the written data to the sort sorting function (priority ).
My work platform is win7 32bit, Visual Studio 2012, Microsoft SQL Server 2008 R2.
Today I learned how to create a SQL database and create a file list (for testing ):
Learn how to connect to SQL in C #
Static void Main (string [] args) {OpenSqlConnection (); // open the database} private static void OpenSqlConnection () {string connectionString = GetConnectionString (); using (SqlConnection connection = new SqlConnection (connectionString) // instantiate the SQL connection class {connection. open (); // Open the Database Console. writeLine ("ServerVersion: {0}", connection. serverVersion); Console. writeLine ("State: {0}", connection. state) ;}} static private string GetConnectionString () {// To avoid storing the connection string in your code, // you can retrieve it from a configuration file, using the // System. configuration. configurationSettings. deleetaskproperty return "Data Source = .; initial Catalog = STUDENT; Integrated Security = SSPI; "; // SQL Server link string}
Test run:
To export the selected data from the database (part of the Code ):
Using System; using System. collections. generic; using System. linq; using System. text; using System. threading. tasks; using System. data. sqlClient; using System. data; namespace sqltest {class Program {static void Main (string [] args) {// OpenSqlConnection (); // open the database string connectionString = GetConnectionString (); // SQL Server connection string SqlConnection connection = new SqlConnection (connectionString); // instantiate the SQL connection class string strSQL = "SELECT title FROM FILE "; // SQL statement SqlDataAdapter da = new SqlDataAdapter (strSQL, connection); // create a DataAdapter data adapter instance DataSet ds = new DataSet (); // create a DataSet instance da. fill (ds, "test"); // use the Fill method of DataAdapter (Fill), call the SELECT command/* foreach (DataTable table in ds. tables) {foreach (DataRow row in table. rows) {foreach (DataColumn column in table. columns) {Console. writeLine (row [column]) ;}} */connection. close (); // Close the database}/* private static void OpenSqlConnection () {string connectionString = GetConnectionString (); using (SqlConnection connection = new SqlConnection (connectionString )) // instantiate the SQL link class {connection. open (); // Open the Database Console. writeLine ("ServerVersion: {0}", connection. serverVersion); Console. writeLine ("State: {0}", connection. state) ;}} */static private string GetConnectionString () {// To avoid storing the connection string in your code, // you can retrieve it from a configuration file, using the // System. configuration. configurationSettings. deleetaskproperty return "Data Source = .; initial Catalog = STUDENT; Integrated Security = SSPI; "; // SQL Server link string }}}
In the future, the function aims to match the data retrieved from the database with user input (call match () and send the processed data to the sort () sorting module.