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

  • SEARCH
  • Home
  • 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 7187661
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T18:53:49+00:00 2026-05-28T18:53:49+00:00

I have two methods that do the same thing. The first one makes performance

  • 0

I have two methods that do the same thing. The first one makes performance problems when I use it in multiple insert, for example, and sometimes throws an Input string was in incorrect format exception. The second one works okay. I want to know why this first one has these problems and what’s the difference between the two methods.

First Method:

public DataTable Return_DataTable(string cmdText, CommandType cmdType, 
    Dictionary<string, string> Param_arr)
{
    Open_Connection();
    int return_val = -1;
    DataTable dt = new DataTable();
    command.CommandText = cmdText;
    command.CommandType = cmdType;
    if (cmdType == CommandType.StoredProcedure)
    {
        if (Param_arr != null)
        {
            command.Parameters.Clear();
            if (Param_arr.Count > 0)
            {
                for (IEnumerator<KeyValuePair<string, string>> enumerator = 
                    Param_arr.GetEnumerator(); enumerator.MoveNext(); )
                {
                    param = command.CreateParameter();
                    param.ParameterName = enumerator.Current.Key.ToString();
                    param.Value = enumerator.Current.Value.ToString();
                    command.Parameters.Add(param);
                }
            }
        }
    }
    IfxDataReader dr2;
    try
    {
        dr2 = command.ExecuteReader();
        dt.Load(dr2);
    }
    catch (IfxException ifxEx)// Handle IBM.data.informix : mostly catched
    {
        ErrMappingForInformix.WriteLog("\r\n Error Code: " + 
            ifxEx.Errors[0].NativeError.ToString() +
            "\r\n MEssage: " + ifxEx.Errors[0].Message);

        throw new Exception("ERROR:" + ifxEx.Errors[0].NativeError.ToString() +
            "\r\n MEssage: " + ifxEx.Errors[0].Message);
    }
    catch (Exception ex)// Handle all other exceptions.
    {
        ErrMappingForInformix.WriteLog("\r\n Error Message: " + ex.Message);
        throw new Exception("\r\n Error Message: " + ex.Message);
    }
    finally
    {
        Close_Connection();
    }
    return dt;
}

Second Method :

public DataTable Return_DataTable(IfxCommand cmd, CommandType cmdtype, 
    IfxParameter[] parameters)
{
    Open_Connection();
    DataTable dt = new DataTable();
    cmd.CommandText = cmd.CommandText;
    cmd.CommandType = cmdtype;
    cmd.Connection = connection;
    cmd.CommandTimeout = 100;
    for (int j = 0; j < parameters.Length; j++)
    {
        cmd.Parameters.Add(parameters[j]);
    }
    try
    {
        dt.Load(cmd.ExecuteReader());
    }
    catch (IfxException ifxEx)// Handle IBM.data.informix : mostly catched
    {
        ErrMappingForInformix.WriteLog("\r\n Error Code: " + 
            ifxEx.Errors[0].NativeError.ToString() +
            "\r\n MEssage: " + ifxEx.Errors[0].Message);

        throw new Exception("ERROR:" + ifxEx.Errors[0].NativeError.ToString() +
            "\r\n MEssage: " + ifxEx.Errors[0].Message);
    }
    catch (Exception ex)// Handle all other exceptions.
    {
        ErrMappingForInformix.WriteLog("\r\n Error Message: " + ex.Message);
        throw new Exception("\r\n Error Message: " + ex.Message);
    }
    finally
    {
        Close_Connection();
    }
    return dt;
}
  • 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-28T18:53:50+00:00Added an answer on May 28, 2026 at 6:53 pm

    The second method handles the parameters passed to the procedure as strongly-typed IfxParameter objects (which I assume inherit from dbParameter). The first method stores the same data as a pair of strings, which is a much poorer representation; it contains less metadata- for example the data type of the value is not retained.

    The DbDataParameter includes the following information:

    DbType DbType { get; set; }
    ParameterDirection Direction { get; set; }
    bool IsNullable { get; }
    string ParameterName { get; set; }
    string SourceColumn { get; set; }
    DataRowVersion SourceVersion { get; set; }
    object Value { get; set; }
    byte Precision { get; set; }
    byte Scale { get; set; }
    int Size { get; set; }
    

    The first method which provides only the name and a string representation of the value is forcing ADO.NET to attempt to cast the string to the correct datatype, and either use default values or look at the available metadata to figure out the right values for the other parameters (I don’t remember off the top of my head what the exact behavior is).

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

Sidebar

Related Questions

I have two methods, one that I use to convert an image to a
I have two webservices that have exactly the same methods and signatures but point
I have these two methods on a class that differ only in one method
I have a really simple class with two methods; One that will be called
I have two action methods that are conflicting. Basically, I want to be able
I have the following two methods that (as you can see) are similar in
I have a class that contains two methods like these: public String getFoo(Int32 a)
I'm having trouble grasping generic methods. I have two classes that are generated (they
I have a virtual base class and two classes that implement the various methods.
I have two binary files that are related one to another (meaning, when one

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.