本文整理汇总了C#中SqliteConnection.CreateCommand方法的典型用法代码示例。如果您正苦于以下问题:C# SqliteConnection.CreateCommand方法的具体用法?C# SqliteConnection.CreateCommand怎么用?C# SqliteConnection.CreateCommand使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SqliteConnection
的用法示例。
在下文中一共展示了SqliteConnection.CreateCommand方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Transactions_do_not_throw
public void Transactions_do_not_throw()
{
var path = Path.Combine(ApplicationData.Current.LocalFolder.Path, "test.db");
if (File.Exists(path))
{
File.Delete(path);
}
using (var connection = new SqliteConnection("Filename=" + path))
{
connection.Open();
using (var command = connection.CreateCommand())
{
command.CommandText = @"
DROP TABLE IF EXISTS table1;
CREATE TABLE table1(Id INTEGER PRIMARY KEY, Value INT);
INSERT INTO table1 (Value) VALUES ('transaction test');
BEGIN; -- <<< throws if temp dir not set correctly
INSERT INTO table1 (Value) VALUES ('value 2');
CREATE TABLE temp_table2 ( Id INT, Value TEXT);
INSERT INTO temp_table2 SELECT * FROM table1;";
command.ExecuteNonQuery();
command.CommandText = "SELECT count(*) from temp_table2;";
Assert.Equal(2L, command.ExecuteScalar());
command.CommandText = "ROLLBACK;";
command.ExecuteNonQuery();
command.CommandText = "SELECT count(*) FROM table1;";
Assert.Equal(1L, command.ExecuteScalar());
}
}
}
示例2: SqliteDataAdapter
/// <summary>
/// Initializes a new instance of the <see cref="SqliteDataAdapter">SqliteDataAdapter</see> class
/// with a SelectCommand and a SqliteConnection object.
/// </summary>
/// <param name="selectCommandText"></param>
/// <param name="connection"></param>
public SqliteDataAdapter(string selectCommandText, SqliteConnection connection)
{
#if NET_2_0
DbCommand cmd;
#else
IDbCommand cmd;
#endif
cmd = connection.CreateCommand();
cmd.CommandText = selectCommandText;
SelectCommand = cmd;
}