Q:

How can I add SqlParameters without knowing the name / type?

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.

A:

try here

