Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/256.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如果已成功插入到第一个表中,则将数据插入到第二个表中,否则不';t插入数据_C#_Sqlite - Fatal编程技术网

C# 如果已成功插入到第一个表中,则将数据插入到第二个表中,否则不';t插入数据

C# 如果已成功插入到第一个表中,则将数据插入到第二个表中,否则不';t插入数据,c#,sqlite,C#,Sqlite,我在Sqlite中有两个表我想如果用户在第一个表中插入了数据,那么就在第二个表中插入一个特定的数据,但是如果在第一个表上插入成功,在第二个表上插入失败,那么插入第一个表的数据就必须删除,如何使用Sqlite在c#中管理这一点? 我的意思是,在sqlite或sql中是否有任何方法可以管理此问题?? 下面是我在c#中使用的代码: 您可以在SQLite中使用触发器。 你可以用谷歌轻松搜索。。我做了,下面是一些代码的一部分,这是在谷歌提供的 请注意,下面只是一个例子,下面是完整的答案,您必须阅读附件,可

我在Sqlite中有两个表我想如果用户在第一个表中插入了数据,那么就在第二个表中插入一个特定的数据,但是如果在第一个表上插入成功,在第二个表上插入失败,那么插入第一个表的数据就必须删除,如何使用Sqlite在c#中管理这一点? 我的意思是,在sqlite或sql中是否有任何方法可以管理此问题?? 下面是我在c#中使用的代码:


您可以在SQLite中使用触发器。

你可以用谷歌轻松搜索。。我做了,下面是一些代码的一部分,这是在谷歌提供的

请注意,下面只是一个例子,下面是完整的答案,您必须阅读附件,可能还有几篇关于数据库中事务的文章

     string cs = "URI=file:test.db";        

    using (SqliteConnection con = new SqliteConnection(cs)) 
    {
        con.Open();

        using(SqliteTransaction tr = con.BeginTransaction())
        {
            using (SqliteCommand cmd = con.CreateCommand())
            {

                cmd.Transaction = tr;
                cmd.CommandText = "DROP TABLE IF EXISTS Friends";
                cmd.ExecuteNonQuery();

             ...............

             }

            tr.Commit();
        }

        con.Close();
    }
}

如何让用户知道??如果有办法…只链接答案是不鼓励的。请您在回答中包含链接中的相关部分,这是不完整的;它甚至没有插入任何内容。
     string cs = "URI=file:test.db";        

    using (SqliteConnection con = new SqliteConnection(cs)) 
    {
        con.Open();

        using(SqliteTransaction tr = con.BeginTransaction())
        {
            using (SqliteCommand cmd = con.CreateCommand())
            {

                cmd.Transaction = tr;
                cmd.CommandText = "DROP TABLE IF EXISTS Friends";
                cmd.ExecuteNonQuery();

             ...............

             }

            tr.Commit();
        }

        con.Close();
    }
}