//sql语句批处理
string select = "SELECT COUNT(*) FROM Customers; SELECT COUNT(*) FROM Products";
using (SqlConnection conn = new SqlConnection(source))
{
conn.Open();
SqlCommand cmd = new SqlCommand(select, conn);
using (SqlDataReader reader = cmd.ExecuteReader())
{
int statement = 0;
do
{
statement++;
while (reader.Read())
{
Console.WriteLine("Output from batch statement {0} is {1}", statement, reader[0]);
}
}
while (reader.NextResult());
reader.Close();
}
conn.Close();
}
string select = "SELECT COUNT(*) FROM Customers; SELECT COUNT(*) FROM Products";
using (SqlConnection conn = new SqlConnection(source))
{
conn.Open();
SqlCommand cmd = new SqlCommand(select, conn);
using (SqlDataReader reader = cmd.ExecuteReader())
{
int statement = 0;
do
{
statement++;
while (reader.Read())
{
Console.WriteLine("Output from batch statement {0} is {1}", statement, reader[0]);
}
}
while (reader.NextResult());
reader.Close();
}
conn.Close();
}
浙公网安备 33010602011771号