Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a sqlite database
when execute this command
SQL
Delete from Login;
Delete from Branch;
Delete from UserType;
Delete from Permision; 
Delete from GroupPermision;

Don't delete all data from tables
So I want to catch the Error

What I have tried:

I tried to use Transaction but didn't know how to catch the error
Posted
Updated 15-Oct-20 23:51pm
Comments
Richard MacCutchan 16-Oct-20 5:17am    
What language and code are you using?

1 solution

A Transaction won't catch an error, it allows you to recover gracefully from an error by using ROLLBACK to undo all the changes.

To catch the error will depend on the language you are accessing SQLite from.
For example, in C#:
C#
using (SQLiteConnection con = new SQLiteConnection(strConnect))
    {
    con.Open();
    using (SQLiteTransaction trans = con.BeginTransaction())
        {
        using (SQLiteCommand cmd = new SQLiteCommand("DELETE FROM Login", con))
            {
            try
                {
                sqCommand.ExecuteNonQuery();
                sqCommand.CommandText = "DELETE FROM Branch";
                sqCommand.ExecuteNonQuery();
                trans.Commit();
                }
            catch(Exception e)
                {
                trans.Rollback();
                ... report problem, or log it ...
                }
            }
        }
    }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900