如何自动从SQLServer获取表单名称

时间:2018-02-20 07:56:37

标签: c#

我想从数据库中添加菜单项。

例如,当我将菜单名称添加到数据库中时。它会自动定位。

在表格内部,我有3列。

ID, FormName, DisplayName.

我该怎么办? 感谢。

1 个答案:

答案 0 :(得分:0)

目前还不是很清楚你的意思,但是:你可以隐式地查询表的架构<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.leosoftsys</groupId> <artifactId>bpsp-kpi-bp-check</artifactId> <version>0.0.1</version> <packaging>jar</packaging> <name>bpsp-kpi-bp-check</name> <description>Business Check For BPS+</description> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.8.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> <spring-cloud.version>Dalston.SR4</spring-cloud.version> <vaadin.version>8.1.1</vaadin.version> </properties> <repositories> <repository> <id>vaadin-addons</id> <url>http://maven.vaadin.com/vaadin-addons</url> </repository> </repositories> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-actuator-docs</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <scope>runtime</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-oauth2</artifactId> </dependency> <dependency> <groupId>org.springframework.security.oauth</groupId> <artifactId>spring-security-oauth2</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-security</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-zuul</artifactId> </dependency> <dependency> <groupId>com.h2database</groupId> <artifactId>h2</artifactId> </dependency> <dependency> <groupId>com.vaadin</groupId> <artifactId>vaadin-spring-boot-starter</artifactId> </dependency> <!-- https://mvnrepository.com/artifact/commons-net/commons-net --> <dependency> <groupId>commons-net</groupId> <artifactId>commons-net</artifactId> <version>3.6</version> </dependency> <!-- https://mvnrepository.com/artifact/com.jcraft/jsch --> <dependency> <groupId>com.jcraft</groupId> <artifactId>jsch</artifactId> <version>0.1.54</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> <!-- https://mvnrepository.com/artifact/org.springframework.data/spring-data-jpa --> <dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-jpa</artifactId> <version>1.11.6.RELEASE</version> </dependency> <!-- https://mvnrepository.com/artifact/org.hibernate.javax.persistence/hibernate-jpa-2.0-api --> <!-- <dependency> <groupId>org.hibernate.javax.persistence</groupId> <artifactId>hibernate-jpa-2.0-api</artifactId> <version>1.0.1.Final</version> </dependency> --> <dependency> <groupId>org.vaadin.addon</groupId> <artifactId>confirmdialog</artifactId> <version>3.2.0</version> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-eureka</artifactId> </dependency> <dependency> <groupId>com.fasterxml.jackson.module</groupId> <artifactId>jackson-module-parameter-names</artifactId> </dependency> <dependency> <groupId>com.fasterxml.jackson.datatype</groupId> <artifactId>jackson-datatype-jdk8</artifactId> </dependency> <dependency> <groupId>com.fasterxml.jackson.datatype</groupId> <artifactId>jackson-datatype-jsr310</artifactId> </dependency> <dependency> <groupId>com.vaadin</groupId> <artifactId>vaadin-themes</artifactId> </dependency> <dependency> <groupId>com.vaadin</groupId> <artifactId>vaadin-sass-compiler</artifactId> <version>0.9.13</version> </dependency> <dependency> <groupId>net.jodah</groupId> <artifactId>failsafe</artifactId> <version>1.0.4</version> </dependency> <dependency> <groupId>org.zalando</groupId> <artifactId>failsafe-actuator</artifactId> <version>0.4.1</version> </dependency> <!-- https://mvnrepository.com/artifact/org.json/json --> <dependency> <groupId>org.json</groupId> <artifactId>json</artifactId> <version>20171018</version> </dependency> <!-- <dependency> <groupId>com.vaadin</groupId> <artifactId>vaadin-push</artifactId> <version>${vaadin.version}</version> </dependency> --> </dependencies> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>${spring-cloud.version}</version> <type>pom</type> <scope>import</scope> </dependency> <dependency> <groupId>com.vaadin</groupId> <artifactId>vaadin-bom</artifactId> <version>${vaadin.version}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <build> <resources> <resource> <directory>src/main/webapp</directory> </resource> <resource> <directory>src/main/resources</directory> </resource> </resources> <testResources> </testResources> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> <plugin> <groupId>com.vaadin</groupId> <artifactId>vaadin-maven-plugin</artifactId> <version>${vaadin.version}</version> <executions> <execution> <goals> <goal>clean</goal> <goal>resources</goal> <goal>update-theme</goal> <goal>update-widgetset</goal> <goal>compile-theme</goal> <goal>compile</goal> </goals> </execution> </executions> </plugin> </plugins> </build> </project> ,也许是select * from SomeTable,或者一个where 1=0选项可以禁用行返回) - 然后查看SETIDataReader,或者您查询它以了解布局;或者更好:通过查询元表 - DataTable等等。一旦知道了列名和类型,就可以编写一个基于此做适度事情的UI。如果需要其他配置,SQL Server的“扩展属性”功能允许您将表,列等的其他元数据存储为名称/值字符串对 - 基本上类似于C#中的INFORMATION_SCHEMA.COLUMNS;例如,许多UI工具使用[SomeAttribute(...)]键/值对来保存数据库实体(表,列等)的描述性标签 - 非常类似于MS_Description。将所有这些放在一起可以让事情几乎不能容忍通过将基本控件添加到每个列/字段与名称和标题匹配,但是:基于原始数据库模式的UI通常非常不满意,并且对于最实际的工作,你需要一个自定义用户界面,其中包含适合你当时正在进行的操作的逻辑和设计考虑因素。