Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 746795
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T14:07:55+00:00 2026-05-14T14:07:55+00:00

using (IDbCommand command = new SqlCommand()) { IDbDataAdapter adapter = new SqlDataAdapter(); DataSet ds

  • 0
  using (IDbCommand command = new SqlCommand())
         {
             IDbDataAdapter adapter = new SqlDataAdapter();
             DataSet ds = new DataSet();
             adapter.SelectCommand = command;
             command.Connection = _dataAccess.Connection;
             command.CommandType = CommandType.StoredProcedure;
             command.CommandText = "GetProcData";
             command.Parameters.Add(new SqlParameter("@ProcID  ", procId));

            adapter.Fill(ds);
            return ds.Tables[0].AsEnumerable();
         }

This returns an IEnumerable DataRow The question is that since the return is within the using statement, will it property dispose of the IDBCommand? I know I can easily refactor this so I change the scope of the DataSet outside of the using, but it is more of a wonder than anything else.

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T14:07:55+00:00Added an answer on May 14, 2026 at 2:07 pm

    Yes, this will work as expected with IDbCommand being properly disposed. The compiler will transform the using block to a try-catch-finally, where Dispose is invoked in the finally block.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

using (DbCommand command = oconn.CreateCommand()) { command.CommandText = CREATE TABLE [Sheet2$] (F1 number, F2
I am using following code to setup connection string: ConfigurationSourceBuilder builder = new ConfigurationSourceBuilder
Here's a simplified version of my example: using (DbCommand cmd = new SqlCommand(myProcedure, (SqlConnection)DataAccessHelper.CreateDatabase().CreateConnection())
Using the Redis info command, I am able to get all the stats of
I am using this code to make a Simple Command: public class SimpleCommand :
DbCommand command = new OracleCommand( insert into hardware (HardwareID) VALUES (6);, myConnection); command.ExecuteNonQuery(); Hardware
Preamble: All data connection strings, connections, etc are created using DbProviderFactories. Code is mixed
I want to write a CommandProcessor using generics. The idea being that a Command
I have the following (simplified) code: IDbConnection connection = new SQLiteConnection(GetConnectionString()); if (connection.State ==
I am new to WPF and i am using WPF Model-View-ViewModel Toolkit 0.1 to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.