生成Create Table语句

        /// 
        /// 生成Create Table 语句
        /// 
        /// 
        /// 
        /// 
        private string GetCreateTableSql(FieldSetingList cols, string tableName)
        {

            List colDefs = new List();
            colDefs.Add("OBJECT_ID nvarchar(38)");
            for (int i = 0; i < cols.Count; i++)
            {
                string fieldName = cols[i].FieldName;
                string fieldType = "text";
                switch (cols[i].FieldType)
                {
                    case "System.String":
                        fieldType = string.Format("nvarchar({0})", cols[i].FieldLenth);
                        break;
                    case "System.Decimal": //??????????????????
                        fieldType = "integer";
                        break;
                    default:
                        break;
                }

                colDefs.Add(string.Format("{0} {1}", fieldName, fieldType));
            }
            string result = string.Format("create table {0} ({1})"
                , tableName
                , string.Join(",", colDefs.ToArray()));
            return result;
        }

 

你可能感兴趣的:(生成Create Table语句)