通过SQL查询更改列的描述 [英] Change via SQL Query the description of a column

查看:89
本文介绍了通过SQL查询更改列的描述的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以通过SQL语句更改AccesDb列后面的描述? 更准确地说: 如何在C#中使用SQL为Access表中的列插入描述?

Is it possible to change with a SQL statement the description behind a column from a AccesDb? To be more accurate: How can I insert a description for a column in an Access table using SQL in C#?

推荐答案

无法使用SQL命令设置或更改字段的描述.

It is not possible to set or change the description of a field using SQL commands.

MS Access数据库包含纯数据库元素,例如和它们的(字段).两者都具有与数据库相关的纯属性,例如数据类型字段大小必需属性, em>默认值设置或验证规则.应该可以使用SQL来管理所有这些事情.

An MS Access database contains pure database elements like tables and their columns (fields). Both have pure database-related properties like a data type, a field size, a required property, a default value setting or a validation rule. It should be possible to manage all these things using SQL.

但是……

这只是MS Access数据库可以包含的内容的很小一部分. Access数据库中的大多数对象都是围绕这些纯数据库事物构建的,以在用户友好的用户界面中显示表中的数据,并让用户/开发人员创建自定义的前端以在数据库中显示和管理数据.标准数据表(这是一种特殊的预定义访问 form ),或者使用更复杂且用户定义的 forms 报告.

This is only a very small part of what an MS Access database can contain. Most of the objects in an Access database are built around these pure database things to display the data in the tables in a user-friendly user interface and let the user/developer create a custom front-end to either show and manage the data in a standard data sheet (which is a special kind of pre-defined Access form) or in more complex and user-defined forms and reports.

为支持用户围绕数据设计自定义用户界面,Microsoft不仅定义了新的对象类型(例如 forms reports ),而且还为对象添加了一些属性在数据层上,当在 TextBox ComboBox 等控件中显示或编辑数据时非常有用.其中一些属性是 Input Mask 格式说明.它们与数据的存储无关,而是用于视觉效果.这些属性无法使用SQL进行管理,但可以使用DAO之类的库以编程方式进行定义和更改,其中每个 field 都有一个 properties集合,该集合不仅包含原始属性来自数据层,还包括为支持Microsoft Access的可视"部分而添加的其他属性.

To support users in designing a custom user interface around the data, Microsoft has not only defined new object types like forms and reports but also added several properties to the objects on the data layer that are useful when displaying or editing the data in controls like TextBox, ComboBox etc. Some of these properties are Input Mask, Format or Description. They have nothing to do with the storage of the data but instead serve for something visual. These properties can’t be managed using SQL but can be defined and changed programmatically using a library like DAO where each field has a properties collection that does not only contain the original properties from the data layer but also the additional properties that were added to support the "visual" part of Microsoft Access.

已添加:

VBA中的一个示例可能看起来像这样,将其转换为C#应该不太困难:

An example in VBA could look something like this, it shouldn't be too difficult to translate it into C#:

Sub SetDescription(TableName As String, FieldName As String, Description As String)

    With CurrentDb
        With .TableDefs(TableName)
            With .Fields(FieldName)
                On Error GoTo Err_SetDescription
                .Properties("Description").Value = Description
            End With
        End With
    End With

Exit_SetDescription:
    Exit Sub

Err_SetDescription:
    Select Case Err.Number
        Case 3270
            With CurrentDb
                With .TableDefs(TableName)
                    With .Fields(FieldName)
                        .Properties.Append .CreateProperty("Description", dbText, Description)
                        Resume Next
                    End With
                End With
            End With
        Case Else
            MsgBox Err.Description, vbExclamation
            Resume Exit_SetDescription
    End Select

End Sub

这篇关于通过SQL查询更改列的描述的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆