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 6096547
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:56:24+00:00 2026-05-23T12:56:24+00:00

I have 2 classes. With the Generic Data Access class I can get the

  • 0

I have 2 classes. With the Generic Data Access class I can get the departments from the stored procedure GetDepartments. My problem is that in the Catalog Access class and especially in the public static DataTable ExecuteSelectCommand(DbCommand command)(execute a command and returns the results as a DataTable object) I dont know what I must write in the CATCH loop or how to leave it blank.Can anyone please help me to complete this part?Or maybe how can i change it without Try-catch.

using System;    
using System.Data;    
using System.Data.Common;    
using System.Configuration;    

public static class GenericDataAccess    
{    
  static GenericDataAccess()
  {

  }


  public static DataTable ExecuteSelectCommand(DbCommand command)    
  {    
    DataTable table;

    try    
    { 

      command.Connection.Open();    
      DbDataReader reader = command.ExecuteReader();    
      table = new DataTable();          
      table.Load(reader);          
      reader.Close();        
    }    
    catch (...)    
    {    
      ......
    }    
    finally    
    {         
      command.Connection.Close();    
    }

    return table;    
  }

  public static DbCommand CreateCommand()    
  {    
    string dataProviderName = BalloonShopConfiguration.DbProviderName;   
    string connectionString = BalloonShopConfiguration.DbConnectionString;

    DbProviderFactory factory = DbProviderFactories.GetFactory(dataProviderName);    
    DbConnection conn = factory.CreateConnection();

    conn.ConnectionString = connectionString;

    DbCommand comm = conn.CreateCommand();    
    comm.CommandType = CommandType.StoredProcedure;

    return comm;
  }
}

**The Catalog Access class:**

using System;    
using System.Data;    
using System.Data.Common;

public static class CatalogAccess    
{    
  static CatalogAccess()
  {

  }

  public static DataTable GetDepartments()    
  {    
    DbCommand comm = GenericDataAccess.CreateCommand();

    comm.CommandText = "GetDepartments";

    return GenericDataAccess.ExecuteSelectCommand(comm);    
  }    
}
  • 1 1 Answer
  • 0 Views
  • 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-23T12:56:24+00:00Added an answer on May 23, 2026 at 12:56 pm

    If you don’t know what to do or don’t want to handle any exceptions, leave with catch out. This is valid:

    try
    {
        // code here
    }
    finally
    {
        // cleanup here
    }
    

    ..that way, any exceptions will be passed up to the method that called your method. If there is a problem (exception) in the try block, the method will exit, but not before any code in finally is executed.

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

Sidebar

Related Questions

I have classes that store data, and methods to go get data for individual
I have multiple classes that all derive from a base class, now some of
I have a data access library that has a few classes that all implement
I want to access certain form elements from classes that normally don't have access
I have a generic class in my project with derived classes. public class GenericClass<T>
I have two classes, Foo and Bar, that have constructors like this: class Foo
Here's my problem: I am creating a Blackberry application that access's my data via
I have a project that I'm upgrading from 2008 to 2010. My problem is
I have a bunch of generic interfaces and classes public interface IElement { //
i have a few classes that i am trying to move to using generics

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.