日期:2014-05-17 浏览次数:20552 次
public static Object exec(string sql, List<SqlParameter> sqlpar, CommandType cmdType, int? OutputIndex)
{
using (conn=new SqlConnection(connStr))
{
cmd = new SqlCommand(sql, conn);
cmd.Parameters.AddRange(sqlpar.ToArray());
cmd.CommandType = cmdType;
if (OutputIndex!=null)
{
cmd.Parameters[(int)OutputIndex].Direction = ParameterDirection.Output;
}
try
{
if (conn.State!=ConnectionState.Open)
{
conn.Open();
}
cmd.ExecuteNonQuery();
if (OutputIndex!=null)
{
return cmd.Parameters[(int)OutputIndex].Value;
}
return null;
}
catch (Exception ex)
{
throw ex;
}
finally
&nb