Adding parameters to IDbCommand

前端 未结 6 645
被撕碎了的回忆
被撕碎了的回忆 2020-12-30 18:43

I am creating a small helper function to return a DataTable. I would like to work across all providers that ADO.Net supports, so I thought about ma

6条回答
  •  梦毁少年i
    2020-12-30 19:17

    You could add the code of the accepted answer to an extension method:

    public static class DbCommandExtensionMethods
    {
        public static void AddParameter (this IDbCommand command, string name, object value)
        {
            var parameter = command.CreateParameter();
            parameter.ParameterName = name;
            parameter.Value = value;
            command.Parameters.Add(parameter);
        }
    }
    

提交回复
热议问题