本文整理匯總了C#中System.Test.ExecuteQuery方法的典型用法代碼示例。如果您正苦於以下問題:C# Test.ExecuteQuery方法的具體用法?C# Test.ExecuteQuery怎麽用?C# Test.ExecuteQuery使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Test
的用法示例。
在下文中一共展示了Test.ExecuteQuery方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: ExecuteCommandTest
/// <summary>
/// 測試直接執行 SQL 語句.
/// </summary>
private static void ExecuteCommandTest()
{
Test context = new Test(connString);
Console.WriteLine("手動執行 SQL : INSERT INTO TestMain(id, value) VALUES (4, 'FOUR') ");
int r1 = context.ExecuteCommand("INSERT INTO TestMain(id, value) VALUES (4, 'FOUR') ");
Console.WriteLine("執行結果:{0}", r1);
Console.WriteLine("手動執行 SQL : SELECT * FROM TestMain WHERE id = 4 ");
var mainData = context.ExecuteQuery<TestMain>("SELECT * FROM TestMain WHERE id = 4");
foreach (TestMain data in mainData)
{
Console.WriteLine("Main[{0}, {1}]", data.Id, data.Value);
}
Console.WriteLine("手動執行 SQL : DELETE TestMain WHERE id = 4");
int r2 = context.ExecuteCommand("DELETE TestMain WHERE id = 4");
Console.WriteLine("執行結果:{0}", r2);
}
示例2: ExecuteQueryTest
/// <summary>
/// 測試直接執行 SQL 語句.
/// </summary>
private static void ExecuteQueryTest()
{
Test context = new Test(connString);
Console.WriteLine("手動執行 SQL : SELECT * FROM test_main WHERE id = 2 ");
var mainData = context.ExecuteQuery<TestMain>("SELECT * FROM TestMain WHERE id = 2");
foreach (TestMain data in mainData)
{
Console.WriteLine("Main[{0}, {1}]", data.Id, data.Value);
}
}