当前位置: 首页>>代码示例>>C#>>正文


C# StreamReader.AllLines方法代码示例

本文整理汇总了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"));
             }
 }
开发者ID:RainsSoft,项目名称:CsharpSQLite,代码行数:28,代码来源:InsertFixture.cs

示例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));
             }
 }
开发者ID:RainsSoft,项目名称:CsharpSQLite,代码行数:17,代码来源:InsertFixture.cs

示例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();
				}
			}
		}
开发者ID:jcwmoore,项目名称:athena,代码行数:20,代码来源:ForeignKeyConstraintFixture.cs


注:本文中的System.IO.StreamReader.AllLines方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。