Search code examples
c#dapper

C# Dapper QueryFirstOrDefault method with "The method or operation is not implemented" exception


I have a static method like

public static DataRow query_result_to_DataRow()
    {
        DataTable _dt = null;
        using (IDbConnection dbConn = dkCommon.dbConn)
        {
            dbConn.Open();
            try
            {
                _dt = dbConn.QueryFirstOrDefault<DataTable>("select * from tbl_dk_users where user_name like 'admin' and user_pass like '123456'");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

        }
        DataRow _dr = _dt.Rows[0];
        return _dr;
    }

I have exception "Method or operation is not implemented" exception in code

_dt = dbConn.QueryFirstOrDefault<DataTable>(_query, null, null, 600000, null);

Method of dapper QueryFirstOrDefault can't return any data. I don't know where am I wrong...


Solution

  • Trying to retrieve a DataTable using Dapper is an incorrect use of Dapper. If you wish to retrieve a DataTable you don't need to use Dapper at all:

    DataTable _dt = new DataTable();
    _dt.Load(dbConn.ExecuteReader("select * from tbl_dk_users where user_name like 'admin' and user_pass like '123456'"));