Exemplo n.º 1
0
    protected static List <int> EnumRecords(string table, string returnfield, string[] filterfields = null, object[] values = null)
    {
        List <OleDbParameter> pars = new List <OleDbParameter>();

        string where = "";
        if (filterfields != null && filterfields.Length > 0)
        {
            where = " WHERE ";
            for (int i = 0; i < filterfields.Length; i++)
            {
                if (values[i] is Expression)
                {
                    where += string.Format("{0} {1} = {2}", i == 0 ? "" : " AND ", filterfields[i], values[i].ToString());
                }
                else
                {
                    where += string.Format("{0} {1} = ?", i == 0 ? "" : " AND ", filterfields[i]);
                    OleDbParameter p = new OleDbParameter("@" + filterfields[i], OleDbTypeMap.GetType(values[i].GetType()));
                    p.Value = values[i];
                    pars.Add(p);
                }
            }
        }
        string slq = string.Format("SELECT {0} FROM {1} {2}", returnfield, table, where);

        List <int> res = new List <int>();

        foreach (DataRow row in DBHelper.GetDataSet(slq, pars.ToArray()).Tables[0].Rows)
        {
            res.Add(Convert.ToInt32(row[returnfield]));
        }
        return(res);
    }
Exemplo n.º 2
0
    protected static void SQLExecute(string sql, object[] vals = null)
    {
        List <OleDbParameter> pars = new List <OleDbParameter>();

        if (vals != null)
        {
            foreach (object o in vals)
            {
                OleDbParameter p = new OleDbParameter("@par" + pars.Count.ToString(), OleDbTypeMap.GetType(o.GetType()));
                p.Value = o;
                pars.Add(p);
            }
        }
        DBHelper.SQLExecute(sql, pars.ToArray());
    }