예제 #1
0
파일: OdbcTool.cs 프로젝트: iCSJ/WebApi
 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));
 }
예제 #2
0
파일: OdbcTool.cs 프로젝트: iCSJ/WebApi
 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));
 }
예제 #3
0
파일: EntityTool.cs 프로젝트: zanderphh/dcm
        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);
        }