Guest User

Untitled

a guest
Feb 20th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.45 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Data.SqlClient;
  6. using MySql.Data.MySqlClient;
  7.  
  8. namespace ManagementSuite
  9. {
  10. class MSSQL
  11. {
  12. private string UserName;
  13. private string Password;
  14. private string Database;
  15. private string Server;
  16.  
  17. public MSSQL(string server, string username, string password, string database)
  18. {
  19. Server = server;
  20. UserName = username;
  21. Password = password;
  22. Database = database;
  23. }
  24.  
  25. private SqlConnection Connection()
  26. {
  27. SqlConnection Con = new SqlConnection("Server=" + Server + ";" + "User Id=" + UserName + ";" + "password=" + Password + ";" + "database=" + Database + ";");
  28.  
  29. try
  30. {
  31. Con.Open();
  32. }
  33. catch
  34. {
  35. Console.ForegroundColor = ConsoleColor.Red;
  36. Console.Write("[Error] ");
  37.  
  38. Console.ForegroundColor = ConsoleColor.Gray;
  39. Console.WriteLine("Could not connect to MSSQL.");
  40. }
  41.  
  42. return Con;
  43. }
  44.  
  45. protected SqlCommand NonReturnQuery(string Query)
  46. {
  47. SqlCommand Command = new SqlCommand(Query, Connection());
  48. try
  49. {
  50. Command.ExecuteScalar();
  51. }
  52. catch
  53. {
  54. Console.ForegroundColor = ConsoleColor.Red;
  55. Console.Write("[Error] ");
  56.  
  57. Console.ForegroundColor = ConsoleColor.Gray;
  58. Console.WriteLine("Query failed to execute.");
  59. }
  60. return Command;
  61. }
  62.  
  63. //Clean up
  64. ~MSSQL()
  65. {
  66. Connection().Close();
  67. }
  68. }
  69.  
  70. class MySQL
  71. {
  72. private string UserName;
  73. private string Password;
  74. private string Database;
  75. private string Server;
  76.  
  77. public MySQL(string server, string username, string password, string database)
  78. {
  79. Server = server;
  80. UserName = username;
  81. Password = password;
  82. Database = database;
  83. }
  84.  
  85. //Connection
  86. private MySqlConnection Connection()
  87. {
  88. MySqlConnection Con = new MySqlConnection("Server=" + Server + ";" + "User Id=" + UserName + ";" + "password=" + Password + ";" + "database=" + Database + ";");
  89.  
  90. try
  91. {
  92. Con.Open();
  93. }
  94. catch
  95. {
  96. Console.ForegroundColor = ConsoleColor.Red;
  97. Console.Write("[Error] ");
  98.  
  99. Console.ForegroundColor = ConsoleColor.Gray;
  100. Console.WriteLine("Could not connect to MySQL.");
  101. }
  102.  
  103. return Con;
  104. }
  105.  
  106. //Query
  107. protected MySqlCommand NonReturnQuery(string Query)
  108. {
  109. MySqlCommand Command = new MySqlCommand(Query, Connection());
  110. try
  111. {
  112. Command.ExecuteScalar();
  113. }
  114. catch
  115. {
  116. Console.ForegroundColor = ConsoleColor.Red;
  117. Console.Write("[Error] ");
  118.  
  119. Console.ForegroundColor = ConsoleColor.Gray;
  120. Console.WriteLine("Query failed to execute.");
  121. }
  122. return Command;
  123. }
  124.  
  125. protected string[] ReturnQuery(string Query)
  126. {
  127. string[] Data = null;
  128. MySqlDataReader Reader;
  129. MySqlCommand Command = new MySqlCommand(Query, Connection());
  130. try
  131. {
  132. Reader = Command.ExecuteReader();
  133. Data = new string[Reader.FieldCount];
  134. while (Reader.Read())
  135. {
  136. for (int x = 0; x < Reader.FieldCount; x++)
  137. {
  138. Data[x] = Convert.ToString(Reader[x]);
  139. }
  140. }
  141. }
  142. catch
  143. {
  144. Console.ForegroundColor = ConsoleColor.Red;
  145. Console.Write("[Error] ");
  146.  
  147. Console.ForegroundColor = ConsoleColor.Gray;
  148. Console.WriteLine("Query failed to execute.");
  149. }
  150. return Data;
  151. }
  152.  
  153. //Clean up
  154. ~MySQL()
  155. {
  156. Connection().Close();
  157. }
  158. }
  159. }
Add Comment
Please, Sign In to add comment