public string CreateEntity(string strTableName) { string strSql = string.Format("Select systypes.name AS TypeName,SysColumns.name AS ColName,ISNULL(sys.extended_properties.value,'') as Remark From SysColumns" + " LEFT JOIN systypes ON SysColumns.xtype = systypes.xtype" + " LEFT JOIN sys.extended_properties ON sys.extended_properties.major_id = SysColumns.id AND sys.extended_properties.minor_id = SysColumns.colorder" + " Where id = Object_Id('{0}')", strTableName); SqlCommand sqlCommand = new SqlCommand(strSql, sqlConnection); if (sqlConnection.State == System.Data.ConnectionState.Closed) { sqlConnection.Open(); } SqlDataReader sqlDataReader = sqlCommand.ExecuteReader(); List <string> listColName = new List <string>(); List <string> listColRemark = new List <string>(); List <string> listType = new List <string>(); while (sqlDataReader.Read()) { listColName.Add(sqlDataReader["ColName"].ToString()); listColRemark.Add(sqlDataReader["Remark"].ToString()); listType.Add(GetCSharpDataType(sqlDataReader["TypeName"].ToString())); } sqlDataReader.Close(); return(EntityCreator.CreateEntity(strTableName, listColName, listType, listColRemark)); }
private void btnCreate_Click(object sender, EventArgs e) { string strTableName = combTableList.Text; ICreate create = new MSSQLCreate(); create.ConnDB(); string str = create.CreateEntity(strTableName); EntityCreator.SaveStrToFile(str, strTableName); }