Catching Exception inside Using statement

后端 未结 9 808
不知归路
不知归路 2021-02-04 01:27

I know that Using statement disposes out the object that is being created. Like if I wanted to do something like this:

    Using(SqlConnection conn = new SqlConn         


        
9条回答
  •  南旧
    南旧 (楼主)
    2021-02-04 02:22

    Thats just the same way you would do it without.

    using(SqlConnection conn = new SqlConnection(connString))
    {
      try{
        //some code
      }
      catch(SqlException e)
        MessageBox.Show(e.Message);
    }
    

提交回复
热议问题