Advertisement
Guest User

Untitled

a guest
May 16th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using MySql.Data.MySqlClient;
  7. using System.Data;
  8.  
  9. namespace DBConnectionTest
  10. {
  11. class Program
  12. {
  13. static void Main(string[] args)
  14. {
  15. string connectionString = "datasource=localhost;port=3306;username=root;password=ece426spring2017";
  16. String getStringCmd = "SELECT first_name FROM sakila.actor";
  17.  
  18. MySqlConnection connection = new MySqlConnection(connectionString);
  19. MySqlDataAdapter da = new MySqlDataAdapter(getStringCmd, connection);
  20. DataSet ds = new DataSet();
  21. da.Fill(ds);
  22.  
  23. List<string> keyValues = new List<string>();
  24. foreach (DataRow row in ds.Tables[0].Rows)
  25. {
  26. keyValues.Add(row["first_name"].ToString());
  27. }
  28.  
  29. string a = "and abc asd dsa efg";
  30. string matchedKeys = string.Empty;
  31. bool matchFound = false;
  32.  
  33.  
  34. foreach (string key in keyValues)
  35. {
  36. if (a.Contains(key))
  37. {
  38. matchFound = true;
  39. matchedKeys += key + ",";
  40. }
  41. }
  42.  
  43. if (matchFound)
  44. Console.Write("MATCH");
  45.  
  46. else
  47. Console.WriteLine("NO MATCH");
  48. //var list = new List<string>();
  49. //MySqlCommand command = new MySqlCommand(getStringCmd, connection);
  50. //connection.Open();
  51. //MySqlDataReader reader = command.ExecuteReader();
  52.  
  53. //while (reader.Read())
  54. //{
  55. // list.Add(reader["first_name"].ToString());
  56. //}
  57. //reader.Close();
  58.  
  59. //Console.Write(list);
  60. }
  61. }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement