Sql-Net ExecuteScalarAsync Usage Example

Has anyone got an example that works, or can point out the missing piece in this puzzle, basically the snippet below (on a completely empty, just created database), generates the following output;

2014-02-13 22:48:26.776 BabyBioTests[43477:5c03] Created Async DB

2014-02-13 22:48:26.780 BabyBioTests[43477:5c03] Done with DBVersion Async

Basically it completely ignores the count(Id) query (which should return 0 as the table is empty), it just silently ignored the whole block, it's late and I'm tired - help!

    _conn.CreateTableAsync<DBVersion>().ContinueWith (x => {

        Console.WriteLine("Created Async DB");

        _conn.ExecuteScalarAsync<int> ("select count(Id) from DBVersion", null).ContinueWith ( t => {

            if(t.Result == 0)
            {
                Console.WriteLine ("No DBVersion Record");

            } else {
                Console.WriteLine ("DBVersion Found");

            }

        });
        Console.WriteLine ("Done with DBVersion Async");

   }); //end create table

Best Answer

  • AndyFlisherAndyFlisher GB ✭✭✭
    Accepted Answer

    Solved it, lose the 'null' parameter in the execute command, that was taken from the documentation so assumed it was valid!

Answers

  • AndyFlisherAndyFlisher GBBeta, University ✭✭✭
    Accepted Answer

    Solved it, lose the 'null' parameter in the execute command, that was taken from the documentation so assumed it was valid!

  • Agreed, why put the null in the docs. Had me confused for a while, thank you for solving this.

Sign In or Register to comment.