本文整理汇总了C#中CUBRID.Data.CUBRIDClient.CUBRIDConnection.BatchExecuteNoQuery方法的典型用法代码示例。如果您正苦于以下问题:C# CUBRIDConnection.BatchExecuteNoQuery方法的具体用法?C# CUBRIDConnection.BatchExecuteNoQuery怎么用?C# CUBRIDConnection.BatchExecuteNoQuery使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CUBRID.Data.CUBRIDClient.CUBRIDConnection
的用法示例。
在下文中一共展示了CUBRIDConnection.BatchExecuteNoQuery方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BatchExecuteNoQuery_Test
public void BatchExecuteNoQuery_Test()
{
using (CUBRIDConnection conn = new CUBRIDConnection())
{
LogTestStep("Test BatchExecute with serveral non-query sql statements");
conn.ConnectionString = DBHelper.connString;
conn.Open();
DBHelper.ExecuteSQL("drop table if exists t", conn);
string[] sql_arr = new string[4];
sql_arr[0] = "create table t(id integer)";
sql_arr[1] = "insert into t values(11)";
sql_arr[2] = "insert into t values(22)";
sql_arr[3] = "insert into t values(33)";
int result = conn.BatchExecuteNoQuery(sql_arr);
Assert.AreEqual(4, result);
string sql = "select * from t";
using (CUBRIDCommand cmd = new CUBRIDCommand(sql, conn))
{
using (DbDataReader reader = cmd.ExecuteReader())
{
for (int i = 1; i < 4; i++)
{
reader.Read();
Assert.AreEqual(i * 11, reader.GetInt32(0));
}
LogStepPass();
}
}
LogTestStep("Test BatchExecute with null");
try
{
result = conn.BatchExecuteNoQuery(null);
Log("The expected exception is not thrown: Object reference not set to an instance of an object.");
LogStepFail();
}
catch (CUBRIDException ex)
{
Log(ex.Message);
Assert.AreEqual("Object reference not set to an instance of an object.", ex.Message);
LogStepPass();
}
//revert the test db
DBHelper.ExecuteSQL("drop table t;", conn);
LogTestResult();
}
}
示例2: Test_BatchExecuteNoQuery
/// <summary>
/// Test CUBRIDConnection BatchExecuteNoQuery() method
/// </summary>
private static void Test_BatchExecuteNoQuery()
{
using (CUBRIDConnection conn = new CUBRIDConnection())
{
conn.ConnectionString = TestCases.connString;
conn.Open();
string[] sqls = new string[3];
sqls[0] = "create table t(id int)";
sqls[1] = "insert into t values(1)";
sqls[2] = "insert into t values(2)";
conn.BatchExecuteNoQuery(sqls);
string sql = "select count(*) from t";
using (CUBRIDCommand cmd = new CUBRIDCommand(sql, conn))
{
using (DbDataReader reader = cmd.ExecuteReader())
{
reader.Read();
Debug.Assert(reader.GetInt32(0) == 2);
}
}
TestCases.ExecuteSQL("drop table t", conn);
}
}