gpt4 book ai didi

c# - sqlConnection/Command 使用语句 + try/catch block

转载 作者:太空狗 更新时间:2023-10-29 22:59:28 27 4
gpt4 key购买 nike

<分区>

try/catch inside using 或 using inside try/catch 的正确方法是什么?

using (SqlConnection connection = CreateSqlConnection(connString))
{
using (SqlCommand command = CreateSqlCommand()
{
try{//open connection + execute command + do something else}
catch{//do something}
}
}

对比

try
{
using (SqlConnection connection = CreateSqlConnection(connString))
{
using (SqlCommand command = CreateSqlCommand()
{
//open connection + execute command + do something else
}
}
}
catch
{
//do something
}

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com