/// <summary>
/// 生成SqlParameter参数
/// </summary>
/// <param name="paramStr">多个参数组成的串</param>
/// <param name="addReturnParam">是否增加返回参数</param>
/// <param name="values">字段的值一维array</param>
/// <returns>SqlParameter[]</returns>
public static SqlParameter[] GetSqlParams(string paramStr, bool addReturnParam, params object[] values)
{
SqlParameter[] arParams = null;
if ((paramStr != null) && (paramStr.Trim() != ""))
{
string[] paramStrs = paramStr.Split(new Char[] { ',' });
arParams = new SqlParameter[paramStrs.Length];
int i = 0;
foreach (string param in paramStrs)
{
if (values[i] == null)
arParams[i] = new SqlParameter(param.Trim(), DBNull.Value);
else
arParams[i] = new SqlParameter(param.Trim(), values[i]);
i++;
}
}
if (addReturnParam)
{
AddReturnParam(ref arParams, "@ReturnValue", SqlDbType.Int);
}
return arParams;
}
///AddReturnParam函数
public static void AddReturnParam(ref SqlParameter[] arParams, string paramName, SqlDbType ot)
{
SqlParameter newParam = new SqlParameter(paramName.Trim(), ot, 2000);
newParam.Direction = ParameterDirection.ReturnValue;
if (arParams == null)
{
arParams = new SqlParameter[] { newParam };
return;
}
SqlParameter[] newParams = new SqlParameter[arParams.Length + 1];
for (int i = 0; i < arParams.Length; i++)
{
newParams[i] = arParams[i];
}
newParams[arParams.Length] = newParam;
arParams = newParams;
}