Exemplo n.º 1
0
 public int UpdateDataTableUsingTrans(DataTable table, OdbcCommand cmd)
 {
     if (tran == null)
     {
         if (conn.State != ConnectionState.Open)
         {
             conn.Open();
         }
         tran = Conn.BeginTransaction();
     }
     return(OdbcTool.UpdateDataTableUsingTrans(table, tran, cmd));
 }
Exemplo n.º 2
0
 public int ExecuteSqlUsingTrans(string sqlstr, params object[] commandParameters)
 {
     if (tran == null)
     {
         if (conn.State != ConnectionState.Open)
         {
             conn.Open();
         }
         tran = Conn.BeginTransaction();
     }
     return(OdbcTool.ExecuteSqlUsingTrans(sqlstr, tran, commandParameters));
 }
Exemplo n.º 3
0
        public static DataTable EntityListToDataTable <T>(IList <T> entitys, out OdbcCommand cmd)
        {
            string    tableName = GetTableName <T>();
            string    sql       = GetEntitySelectSql <T>() + " where 1=0 ";
            DataTable dt        = OdbcTool.ExecuteDataTable(sql, out cmd);

            if (entitys.Count < 1)
            {
                return(dt);
            }
            PropertyInfo[] propertys = entitys[0].GetType().GetProperties();
            foreach (T entity in entitys)
            {
                DataRow dr = dt.NewRow();
                foreach (PropertyInfo pi in propertys)
                {
                    string colName;
                    Type   type;
                    GetColumnInfo(pi, out colName, out type);
                    if (colName == string.Empty)
                    {
                        colName = pi.Name;
                    }
                    if (dt.Columns.IndexOf(colName) == -1)
                    {
                        throw new Exception(string.Format("[{0}]不存在的列名称:{1}", tableName, colName));
                    }

                    object value = pi.GetValue(entity);
                    if (null != value)
                    {
                        dr[colName] = value;
                    }
                    else
                    {
                        dr[colName] = DBNull.Value;
                    }
                }
                dt.Rows.Add(dr);
            }
            return(dt);
        }