Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Data.SqlClient;
- using MySql.Data.MySqlClient;
- namespace ManagementSuite
- {
- class MSSQL
- {
- private string UserName;
- private string Password;
- private string Database;
- private string Server;
- public MSSQL(string server, string username, string password, string database)
- {
- Server = server;
- UserName = username;
- Password = password;
- Database = database;
- }
- private SqlConnection Connection()
- {
- SqlConnection Con = new SqlConnection("Server=" + Server + ";" + "User Id=" + UserName + ";" + "password=" + Password + ";" + "database=" + Database + ";");
- try
- {
- Con.Open();
- }
- catch
- {
- Console.ForegroundColor = ConsoleColor.Red;
- Console.Write("[Error] ");
- Console.ForegroundColor = ConsoleColor.Gray;
- Console.WriteLine("Could not connect to MSSQL.");
- }
- return Con;
- }
- protected SqlCommand NonReturnQuery(string Query)
- {
- SqlCommand Command = new SqlCommand(Query, Connection());
- try
- {
- Command.ExecuteScalar();
- }
- catch
- {
- Console.ForegroundColor = ConsoleColor.Red;
- Console.Write("[Error] ");
- Console.ForegroundColor = ConsoleColor.Gray;
- Console.WriteLine("Query failed to execute.");
- }
- return Command;
- }
- //Clean up
- ~MSSQL()
- {
- Connection().Close();
- }
- }
- class MySQL
- {
- private string UserName;
- private string Password;
- private string Database;
- private string Server;
- public MySQL(string server, string username, string password, string database)
- {
- Server = server;
- UserName = username;
- Password = password;
- Database = database;
- }
- //Connection
- private MySqlConnection Connection()
- {
- MySqlConnection Con = new MySqlConnection("Server=" + Server + ";" + "User Id=" + UserName + ";" + "password=" + Password + ";" + "database=" + Database + ";");
- try
- {
- Con.Open();
- }
- catch
- {
- Console.ForegroundColor = ConsoleColor.Red;
- Console.Write("[Error] ");
- Console.ForegroundColor = ConsoleColor.Gray;
- Console.WriteLine("Could not connect to MySQL.");
- }
- return Con;
- }
- //Query
- protected MySqlCommand NonReturnQuery(string Query)
- {
- MySqlCommand Command = new MySqlCommand(Query, Connection());
- try
- {
- Command.ExecuteScalar();
- }
- catch
- {
- Console.ForegroundColor = ConsoleColor.Red;
- Console.Write("[Error] ");
- Console.ForegroundColor = ConsoleColor.Gray;
- Console.WriteLine("Query failed to execute.");
- }
- return Command;
- }
- protected string[] ReturnQuery(string Query)
- {
- string[] Data = null;
- MySqlDataReader Reader;
- MySqlCommand Command = new MySqlCommand(Query, Connection());
- try
- {
- Reader = Command.ExecuteReader();
- Data = new string[Reader.FieldCount];
- while (Reader.Read())
- {
- for (int x = 0; x < Reader.FieldCount; x++)
- {
- Data[x] = Convert.ToString(Reader[x]);
- }
- }
- }
- catch
- {
- Console.ForegroundColor = ConsoleColor.Red;
- Console.Write("[Error] ");
- Console.ForegroundColor = ConsoleColor.Gray;
- Console.WriteLine("Query failed to execute.");
- }
- return Data;
- }
- //Clean up
- ~MySQL()
- {
- Connection().Close();
- }
- }
- }
Add Comment
Please, Sign In to add comment