/// <summary> /// 在数据库中创建指定表 /// </summary> public void CreateTable(string connStr, DBTableDetail tableInfo) { //形成SQL语句 StringBuilder strBuilder = new StringBuilder(); string str_create = string.Format("Create Table {0}", tableInfo.TableName); strBuilder.Append(str_create); strBuilder.Append(" ("); int start = 0; if (tableInfo.Columns[0].ColumnType == "int") { if (tableInfo.Columns[0].IsAutoID) { strBuilder.Append(string.Format("{0} int PRIMARY KEY IDENTITY ,", tableInfo.Columns[0].ColumnName)); start = 1; } } for (int i = start; i < tableInfo.Columns.Length; i++) { bool length_fixed = DBSystemHelper.DBType_lengthFixed(tableInfo.Columns[i].ColumnType); string item; if (length_fixed) { item = string.Format("{0} {1} ", tableInfo.Columns[i].ColumnName, tableInfo.Columns[i].ColumnType); } else { item = string.Format("{0} {1}({2}) ", tableInfo.Columns[i].ColumnName, tableInfo.Columns[i].ColumnType); } if ((tableInfo.Columns[i].DefaultValue != null) && (tableInfo.Columns[i].DefaultValue != "")) { item += string.Format("DEFAULT {0}", tableInfo.Columns[i].DefaultValue); } if (tableInfo.Columns[i].IsPkey) { item += "PRIMARY KEY"; } if (i != tableInfo.Columns.Length - 1) { item += " , "; } strBuilder.Append(item); } strBuilder.Append(" )"); //插入数据库 IADOBase adoBase = new SqlADOBase(connStr); adoBase.DoCommand(strBuilder.ToString()); }
/// <summary> /// 得到指定数据库的系统信息 /// </summary> public static DbSysInformation GetDbSysInformation(string dbIP, string user, string pwd, string dbName) { DbSysInformation[] dbInfos = DBSystemHelper.GetAllDbSysInfos(dbIP, user, pwd); for (int i = 0; i < dbInfos.Length; i++) { if (dbInfos[i].Name == dbName) { return(dbInfos[i]); } } return(null); }
/// <summary> /// 判断某个数据库是否存在 /// </summary> public static bool IsDbExist(string dbIP, string user, string pwd, string dbName) { DbSysInformation[] dbInfos = DBSystemHelper.GetAllDbSysInfos(dbIP, user, pwd); for (int i = 0; i < dbInfos.Length; i++) { if (dbInfos[i].Name == dbName) { return(true); } } return(false); }
/// <summary> /// 判断特定的数据库中是否存在某个表 /// </summary> public static bool IsTableExist(string connStr, string tableName) { string[] names = DBSystemHelper.GetAllUserTableNames(connStr); for (int i = 0; i < names.Length; i++) { if (names[i] == tableName) { return(true); } } return(false); }