小编ban*_*nsi的帖子

时间:2019-05-17 标签:c#using不带分号的语句

我在网上找到了以下代码:

using (SqlConnection con = new SqlConnection(connectionString))
    {
        //
        // Open the SqlConnection.
        //
        con.Open();
        //
        // The following code uses an SqlCommand based on the SqlConnection.
        //
        using (SqlCommand command = new SqlCommand("SELECT TOP 2 * FROM Dogs1", con))
        using (SqlDataReader reader = command.ExecuteReader())
        {
        while (reader.Read())
        {
            Console.WriteLine("{0} {1} {2}",
            reader.GetInt32(0), reader.GetString(1), reader.GetString(2));
        }
        }
    }
Run Code Online (Sandbox Code Playgroud)

谁能解释一下为什么使用 (SqlCommand ..) 不以分号结尾。我的第二个问题通常是在使用之后我们必须有 { } 来指示使用变量的范围为什么在这种情况下它丢失了?以及如何、何时处理命令对象?

c# ado.net using

-1
推荐指数
1
解决办法
876
查看次数

标签 统计

ado.net ×1

c# ×1

using ×1