本文整理汇总了C#中System.IO.StreamReader.AllLines方法的典型用法代码示例。如果您正苦于以下问题:C# StreamReader.AllLines方法的具体用法?C# StreamReader.AllLines怎么用?C# StreamReader.AllLines使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.StreamReader
的用法示例。
在下文中一共展示了StreamReader.AllLines方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SimpleInsertTest
public void SimpleInsertTest()
{
using(var con = new SQLiteConnection("Data Source=:memory:"))
using(var cmd = con.CreateCommand())
using(var reader = new StreamReader(Path.Combine("Sql", "People.sql")))
{
con.Open();
cmd.CommandText = reader.AllLines().First();
cmd.ExecuteNonQuery();
cmd.CommandText = "INSERT INTO People VALUES(null,'Singleton',-25.5,'PHU74JVF3MT','ccb52c4a-c96a-4b44-9c40-6faff8f2a04b')";
cmd.ExecuteNonQuery();
cmd.CommandText = "select count(*) from people;";
var ct = cmd.ExecuteScalar();
Assert.That(ct, Is.EqualTo(1));
var guid = new Guid("ccb52c4a-c96a-4b44-9c40-6faff8f2a04b");
cmd.CommandText = string.Format("select * from people where testguid = '{0}'", guid.ToString());
var res = cmd.ExecuteReader();
res.Read();
Assert.That(res["testguid"], Is.EqualTo(guid));
Assert.That(res[4], Is.EqualTo(guid));
Assert.That(res["id"], Is.Not.Null);
Assert.That(res["id"], Is.GreaterThan(0));
Assert.That(res["name"], Is.Not.Null);
Assert.That(res["name"], Is.EqualTo("Singleton"));
Assert.That(res["double"], Is.EqualTo(-25.5M));
Assert.That(res["testtext"], Is.EqualTo("PHU74JVF3MT"));
}
}
示例2: BulkInsert
public void BulkInsert()
{
using(var con = new SQLiteConnection("Data Source=" + _filename))
using(var cmd = con.CreateCommand())
using(var reader = new StreamReader(Path.Combine("Sql", "People.sql")))
{
con.Open();
foreach(var sql in reader.AllLines().Where(s => !string.IsNullOrEmpty(s)))
{
cmd.CommandText = sql;
cmd.ExecuteNonQuery();
}
cmd.CommandText = "select count(*) from people;";
var ct = cmd.ExecuteScalar();
Assert.That(ct, Is.EqualTo(100));
}
}
示例3: SimpleInsertForeignTableTest
public void SimpleInsertForeignTableTest()
{
using (var con = new SQLiteConnection("Data Source=:memory:"))
using (var cmd = con.CreateCommand())
using (var preader = new StreamReader(Path.Combine("Sql", "People.sql")))
using (var sreader = new StreamReader(Path.Combine("Sql", "Shirts.sql")))
{
con.Open();
foreach (var sql in preader.AllLines().Where(s => !string.IsNullOrEmpty(s)))
{
cmd.CommandText = sql;
cmd.ExecuteNonQuery();
}
foreach (var sql in sreader.AllLines().Where(s => !string.IsNullOrEmpty(s)))
{
cmd.CommandText = sql;
cmd.ExecuteNonQuery();
}
}
}