1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
| internal sealed class DatabaseClient : IDisposable
{
private DatabaseManager Manager;
private SqlCommand Command;
private SqlConnection Connection;
public DatabaseClient(DatabaseManager _Manager)
{
Manager = _Manager;
SqlConnection Connection = new SqlConnection(_Manager.ConnectionString);
Command = Connection.CreateCommand();
Connection.Open();
}
public void Dispose()
{
Connection.Close();
Command.Dispose();
Connection.Dispose();
}
public void AddParamWithValue(string sParam, object val)
{
Command.Parameters.AddWithValue(sParam, val);
}
public void ExecuteQuery(string sQuery)
{
Command.CommandText = sQuery;
Command.ExecuteScalar();
Command.CommandText = null;
}
public DataSet ReadDataSet(string Query)
{
DataSet dataSet = new DataSet();
Command.CommandText = Query;
using (SqlDataAdapter SqlDataAdapter = new SqlDataAdapter(this.Command.ToString(), Connection))
// using (MySqlDataAdapter mySqlDataAdapter = new MySqlDataAdapter(this.Command))
{
SqlDataAdapter.Fill(dataSet);
}
Command.CommandText = null;
return dataSet;
}
public DataTable ReadDataTable(string Query)
{
DataTable dataTable = new DataTable();
Command.CommandText = Query;
using (SqlDataAdapter SqlDataAdapter = new SqlDataAdapter(this.Command.ToString(), Connection))
{
SqlDataAdapter.Fill(dataTable);
}
Command.CommandText = null;
return dataTable;
}
public DataRow ReadDataRow(string Query)
{
DataTable dataTable = this.ReadDataTable(Query);
if (dataTable != null && dataTable.Rows.Count > 0)
{
return dataTable.Rows[0];
}
return null;
}
public string ReadString(string Query)
{
Command.CommandText = Query;
string result = this.Command.ExecuteScalar().ToString();
Command.CommandText = null;
return result;
}
public int ReadInt32(string Query)
{
Command.CommandText = Query;
int result = int.Parse(this.Command.ExecuteScalar().ToString());
Command.CommandText = null;
return result;
}
public uint ReadUInt32(string Query)
{
Command.CommandText = Query;
uint result = (uint)this.Command.ExecuteScalar();
Command.CommandText = null;
return result;
}
} |
Partager