自强不息,止于至善

身无半文,心忧天下;手释万卷,神交古人
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

关于ADO.NET

Posted on 2007-10-21 09:34  L.Zhang  阅读(104)  评论(0)    收藏  举报

 

//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();
}