日期:2014-05-17  浏览次数:20552 次

DBHelper类方法求解
本帖最后由 wh_liang 于 2013-01-25 11:58:21 编辑

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