Ejemplo n.º 1
0
        /// <summary>
        /// 得到数据表的数据类型
        /// </summary>
        /// <param name="dt"></param>
        /// <returns></returns>
        public static DataFieldTypeCollection GetDataStruct(DataTable dt)
        {
            DataFieldTypeCollection dtc = new DataFieldTypeCollection();

            foreach (DataColumn dc in dt.Columns)
            {
                DataFieldType t = new DataFieldType();
                t.FiledName          = dc.ColumnName.Trim().Replace("\r", "").Replace("\n", "");
                t.Length             = dc.MaxLength;
                t.FieldParameterName = $"@{t.FiledName}";

                string dataTypeName = dc.DataType.FullName.ToLower();
                if (dataTypeName.Contains("int"))
                {
                    t.Type = "int";
                }
                else if (dataTypeName.Contains("datetime"))
                {
                    t.Type = "datetime";
                }
                else
                {
                    t.Type = "string";
                }

                dtc.Add(t);
            }

            return(dtc);
        }
Ejemplo n.º 2
0
        private static string CreateColumn(DataFieldType dt)
        {
            string column = dt.FiledName;;

            switch (dt.Type.ToLower())
            {
            case "string":
                if (dt.Length == -1)
                {
                    column += " text";
                }
                else
                {
                    column += " nvarchar(" + dt.Length + ")";
                }
                break;

            case "datetime":
                column += " datetime";
                break;

            case "int":
                column += " int";
                break;
            }
            return(column);
        }