I am using Sqlite and Dapper. I need to bypass an exception error and return an empty row when there are no records in the Table or the Database File or Table does not exist.

Ronald Rex 1,666 Reputation points
2023-09-06T19:45:21.7633333+00:00

Hi all Friends,

I am returning rows from a Sqlite/Dapper transaction. And if I run into an exception instead of the application crashing, I would like to return an empty row. Thanks !

Developer technologies .NET .NET MAUI
Developer technologies C#
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Johan Smarius 470 Reputation points MVP
    2023-09-06T20:10:38.51+00:00

    You can wrap your call in a try/catch block and in the catch block return an empty row.


  2. Karen Payne MVP 35,586 Reputation points Volunteer Moderator
    2023-09-07T15:51:58.9033333+00:00

    All these are from me doing simple Google searches

    Database exists

    if(File.Exists("database.db"))
    

    Table exists

    SELECT name FROM sqlite_master WHERE type='table' AND name='{table_name}';
    

    Can not repy to empty row unless I see your C# code.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.