I have created MS Access Database using C# ADOX library. I have created one table with several columns. What I want to achieve is when I insert date in one column, the date format should be YYYY-MM-DD and not MM-DD-YYYY. I know its just display format, but I want to access the property which we set when we open access table in design mode, and for column with date data type, set format as Custom (YYYY-MM-DD). I want this to be set at runtime while creating table only. I wanted to know what should be property name that I should use in order to access and set the format property of column?
我使用C#ADOX库创建了MS Access数据库。我创建了一个包含多个列的表。我想要实现的是当我在一列中插入日期时,日期格式应该是YYYY-MM-DD而不是MM-DD-YYYY。我知道它只是显示格式,但我想访问我们在设计模式下打开访问表时设置的属性,对于具有日期数据类型的列,设置格式为Custom(YYYY-MM-DD)。我希望在创建表时仅在运行时设置它。我想知道应该使用什么属性名称来访问和设置列的format属性?
1 个解决方案
#1
You will be better of using DAO library to do that, if you are targetting only Access DB
如果您仅定位Access DB,则最好使用DAO库来执行此操作
With DAO, you could open the database, recordset & access this property using Columns(colNumber).Properties("Format").
使用DAO,您可以使用Columns(colNumber).Properties(“Format”)打开数据库,记录集并访问此属性。
If you don't know, how to use DAO - let me know.
如果您不知道,如何使用DAO - 请告诉我。
EDIT: VB6 code using DAO to get the Format property
编辑:使用DAO获取Format属性的VB6代码
Dim db As DAO.Database, rst As DAO.Recordset
Set db = OpenDatabase("Path to my MDB file")
Set rst = db.OpenRecordset("select myDateColumn From myTable WHERE 1 = 2")
MsgBox rst.Fields("myDate").Properties("Format").Value
rst.Close
Set rst = Nothing
db.Close
Set db = Nothing
#1
You will be better of using DAO library to do that, if you are targetting only Access DB
如果您仅定位Access DB,则最好使用DAO库来执行此操作
With DAO, you could open the database, recordset & access this property using Columns(colNumber).Properties("Format").
使用DAO,您可以使用Columns(colNumber).Properties(“Format”)打开数据库,记录集并访问此属性。
If you don't know, how to use DAO - let me know.
如果您不知道,如何使用DAO - 请告诉我。
EDIT: VB6 code using DAO to get the Format property
编辑:使用DAO获取Format属性的VB6代码
Dim db As DAO.Database, rst As DAO.Recordset
Set db = OpenDatabase("Path to my MDB file")
Set rst = db.OpenRecordset("select myDateColumn From myTable WHERE 1 = 2")
MsgBox rst.Fields("myDate").Properties("Format").Value
rst.Close
Set rst = Nothing
db.Close
Set db = Nothing