コード例 #1
0
        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;
            }));
        }
コード例 #2
0
        //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);
        }
コード例 #3
0
        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);
        }