public Task <int> CountAsync() { return(Task.Run(() => { int vRecordCount; IDbConnection DataConn = mDataConnector.Connection(); IDbCommand DBcmd = DataConn.CreateCommand(); DBcmd.CommandText = "SELECT COUNT(*) From Guests"; vRecordCount = int.Parse(DBcmd.ExecuteScalar().ToString()); DataConn.Close(); return vRecordCount; })); }
//Creates Database if needed- public bool CreateDB() { IDbConnection vDataConn = mDataConnector.Connection(mDataConnector.ConnectionString); IDbCommand vDBcmd = vDataConn.CreateCommand(); try { vDataConn.Open(); vDBcmd.CommandText = "CREATE DATABASE IF NOT EXISTS `" + mDataConnector.DatabaseName + "`;"; vDBcmd.ExecuteNonQuery(); } catch (Exception e) { Debug.WriteLine($"****** Create DB error: {e} ******"); vDBcmd.Dispose(); vDataConn.Close(); return(false); } vDBcmd.Dispose(); vDataConn.Close(); return(true); }
public async Task <int> CountAsync() { string vSQL = "SELECT COUNT(*) From Guests";; IDbConnection vDataConn = _DataConnector.Connection(); //Gets open connection to Database var vResult = await vDataConn.ExecuteScalarAsync <int>(vSQL); vDataConn.Close(); return(vResult); }