1

I am creating a DB wrapper and am in the need of adding SQL paramters to my stament however I do not know the parameter names or type, how can this be done? I have seen many other libraries do this...

I just want the order of values to be mapped to the stored procedure...I thought the following code would work:

public DataTable ExecuteDataTable(string storedProcName, params object[] args)
{
    SqlCommand cmd = new SqlCommand(storedProcName, conn);
    cmd.CommandType = CommandType.StoredProcedure;

    // inserting params like this does not work...
    for (int i = 0; i < args.Length; i++)
    {
        cmd.Parameters.Insert(i, args[0]);
    }

    DataTable dt = new DataTable();
    dt.Load(cmd.ExecuteReader());

    return dt;
}

Any ideas of how to accomplish this? Note: I know there are other libraries such as the Enterprise Library that already does this, but I'm in a situation where that won't help...

Thanks.

Ivo Coumans
  • 759
  • 8
  • 23
mmattax
  • 27,172
  • 41
  • 116
  • 149

1 Answers1

-2

try here

Community
  • 1
  • 1
Steven Williams
  • 1,014
  • 1
  • 10
  • 16