예제 #1
0
        public List <SimpDataEntery> ExecuteSimpData(DbCommand cmd)
        {
            MyTransaction         tran          = MyTransaction.BeginTransaction(cmd);
            List <SimpDataEntery> simpDbEnterys = new List <SimpDataEntery>();

            try
            {
                using (DbDataReader reader = cmd.ExecuteReader())
                {
                    do
                    {
                        var simpCols = new SimpDataColInf[reader.FieldCount];
                        for (int i = 0, iCnt = reader.FieldCount; i < iCnt; i++)
                        {
                            simpCols[i].Name = reader.GetName(i);
                            var fieldType = reader.GetFieldType(i);
                            if (fieldType != null)
                            {
                                simpCols[i].Type = (DotNetType)Enum.Parse(typeof(DotNetType), fieldType.Name);
                            }
                        }
                        var simpRows = new List <object[]>();
                        while (reader.Read())
                        {
                            object[] objs = new object[reader.FieldCount];

                            for (int i = 0, iCnt = reader.FieldCount; i < iCnt; i++)
                            {
                                if ((objs[i] = reader.GetValue(i)).Equals(DBNull.Value))
                                {
                                    objs[i] = null;
                                }
                                if (objs[i] is DateTime)
                                {
                                    objs[i] = ((DateTime)objs[i]).ToString(CultureInfo.InvariantCulture);
                                }
                            }
                            //_reader.GetValues(_objs);
                            simpRows.Add(objs);
                        }
                        simpDbEnterys.Add(new SimpDataEntery()
                        {
                            Cols = simpCols, Rows = simpRows, Val = DateTime.Now.Ticks
                        });
                    } while (reader.NextResult());
                    reader.Close();
                    tran.Commit();
                }
            }
            catch (Exception e)
            {
                tran.Rollback();
                simpDbEnterys.Add(CreateErrorSimpDataEntery(e.ToString()));
            }
            return(simpDbEnterys);
        }
예제 #2
0
        //返回SQL影响的行数
        public object ExecuteScalar(DbCommand cmd)
        {
            MyTransaction tran = MyTransaction.BeginTransaction(cmd);
            object        ret;

            try
            {
                ret = cmd.ExecuteScalar();
                tran.Commit();
            }
            catch (Exception e)
            {
                tran.Rollback();
                return(e.ToString());
            }
            return(ret);
        }
예제 #3
0
        //返回DataSet对象
        public DataSet ExecuteDataSet(DbCommand cmd)
        {
            DbProviderFactory dbfactory     = DbProviderFactories.GetFactory(DbProviderName);
            DbDataAdapter     dbDataAdapter = dbfactory.CreateDataAdapter();
            DataSet           ds            = new DataSet();
            MyTransaction     tran          = MyTransaction.BeginTransaction(cmd);

            if (dbDataAdapter != null)
            {
                dbDataAdapter.SelectCommand = cmd;
                try
                {
                    dbDataAdapter.Fill(ds);
                    tran.Commit();
                }
                catch (Exception e)
                {
                    tran.Rollback();
                    ds.Tables.Add(CreateErrorTable(e.ToString()));
                }
            }
            return(ds);
        }