示例#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
        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);
        }