/// <summary> /// 创建表 /// </summary> /// <param name="tableName">表名</param> /// <returns></returns> public bool CreateTable(string tableName) { var sqlHelper = new SqlHelper.SqlHelper(); string cmdText = string.Format("\r\n CREATE TABLE {0} \r\n (\r\n\t [ID] INT IDENTITY(1,1) PRIMARY KEY \r\n ) \r\n ", tableName); return(sqlHelper.ExecuteNonQuery(cmdText) > 0 ? true : false); }
/// <summary> /// 添加字段 /// </summary> /// <param name="tableName">表名</param> /// <param name="fieldName">字段名</param> /// <param name="type">字段类型</param> public bool AddField(string tableName, string fieldName, string type) { string cmdText = "ALTER TABLE [" + tableName + "] ADD {0}"; switch (type.ToLower()) { case "int32": cmdText = string.Format(cmdText, "[" + fieldName + "] [int]"); break; case "string": cmdText = string.Format(cmdText, string.Concat(new object[] { "[", fieldName, "] [nvarchar] (", 256, ")" })); break; case "datetime": cmdText = string.Format(cmdText, "[" + fieldName + "] [datetime]"); break; case "boolean": cmdText = string.Format(cmdText, "[" + fieldName + "] [bit]"); break; case "bool": cmdText = string.Format(cmdText, "[" + fieldName + "] [bit]"); break; case "decimal": cmdText = string.Format(cmdText, "[" + fieldName + "] [decimal]"); break; case "nvarchar": cmdText = string.Format(cmdText, string.Concat(new object[] { "[", fieldName, "] [nvarchar] (", 256, ")" })); break; case "varchar": cmdText = string.Format(cmdText, string.Concat(new object[] { "[", fieldName, "] [varchar] (", 256, ")" })); break; case "ntext": cmdText = string.Format(cmdText, "[" + fieldName + "] [ntext]"); break; case "text": cmdText = string.Format(cmdText, "[" + fieldName + "] [text]"); break; case "bit": cmdText = string.Format(cmdText, "[" + fieldName + "] [bit]"); break; case "money": cmdText = string.Format(cmdText, "[" + fieldName + "] [money]"); break; } var sqlHelper = new SqlHelper.SqlHelper(); return(sqlHelper.ExecuteNonQuery(cmdText) == 0 ? false : true); }