【问题标题】:Can I get the SqlConnection from SqlDataAdapter?我可以从 SqlDataAdapter 获取 SqlConnection 吗?
【发布时间】:2012-10-25 18:31:29
【问题描述】:

有什么方法可以从SqlDataAdapter 获取SqlConnection

我原以为会找到 SqlDataAdapter.Connection 属性。

【问题讨论】:

    标签: .net ado.net sqldataadapter


    【解决方案1】:

    查看SelectCommand 或您感兴趣的任何命令。

    【讨论】:

      【解决方案2】:

      SqlDataAdapter 具有属性 SelectCommandSqlCommand 的类型),SelectCommand 具有属性 ConnectionSqlConnection 的类型)。

      【讨论】:

        【解决方案3】:

        可以从相关的SqlCommand中获取。

        取决于设置哪一个:

                adapter.SelectCommand.Connection;
                adapter.InsertCommand.Connection;
                adapter.UpdateCommand.Connection;
                adapter.DeleteCommand.Connection;
        

        【讨论】:

          【解决方案4】:

          使用这个:

          var da = new SqlDataAdapter();
          ....
          string connectionString = da.SelectCommand.Connection.ConnectionString
          

          【讨论】:

            猜你喜欢
            • 2010-09-29
            • 2021-06-18
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2021-04-05
            • 1970-01-01
            • 2016-03-24
            • 1970-01-01
            相关资源
            最近更新 更多