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#?
See Question&Answers more detail:osIs 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#?
See Question&Answers more detail:osIt is not possible to set or change the description of a field using SQL commands.
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.
But…
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.
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.
Added:
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