创建具有小数位的MsAccess(accdb)表数据类型Double [英] Create MsAccess (accdb) table datatype Double with decimal places
问题描述
大家早上好
我正在尝试使用以下代码创建一个accdb表:
私有 Sub CreateTable(TbleName)
cn.ConnectionString = Provider =& cp& 数据源=& tss_DB.Text& ; Jet OLEDB:数据库密码=密码;
cn.Open()
cmd.Connection = cn
cmd.CommandText = 创建表Aa_News(ID计数器) ,Field1 Double)
cmd.ExecuteNonQuery()
cn.Close()
End Sub
这确实成功创建该表但Field1具有以下属性:
字段大小:双倍
格式:
小数位:自动
输入掩码:
标题:
默认值:
验证规则:
验证文本:
必填项:否
索引:否
智能标签:
文字对齐:一般
我需要它是:
场地大小:双倍
格式:固定
小数位:3
输入掩码:
说明:
默认值:
验证规则:
验证文本:
必填:是
索引:否
智能标签:
文字对齐:一般
虽然我看过,但我只能找到设置TEXT类型字段大小。
任何人都可以告诉我如何指定不同数据类型的属性,特别是DECIMAL。
如果我用
CREATE 表 Aa_News(ID计数器,Field1 double (已修复, 3 ))
我收到语法错误。
非常感谢您的帮助
Darrell
相反:
创建 表 Aa_News(ID计数器,Field1 double (已修复, 3 ))
尝试:
创建 表 Aa_News(ID计数器,Field1 double ( 10 , 3 ))
或
CREATE 表 Aa_News(ID计数器,Field1 DECIMAL ( 10 , 3 ))
这很奇怪,但使用VBA和MS ADO 2.8库下面的代码执行没有错误:
CurrentProject.Conne ction.Execute CREATE TABLE AAA(ID COUNTER,Field1 DECIMAL(10,3))
因此,可能无法使用.NET驱动程序(Jet OLEDB)在DDL查询中定义字段的大小和小数位。请阅读: Allen Browne - MS Access提示:DDL代码示例 [ ^ ]
Allen Browne写道:虽然DDL在一些较大的数据库中很重要,但它在Access中的用途有限。您可以创建文本字段,但不能将允许零长度属性设置为否,因此任何查询条件都必须测试Null和零长度字符串。您可以创建是/否字段,但是您得到的是文本框,而不是复选框,因为您无法使用DDL设置显示控件属性。您可以创建日期/时间字段,但不能设置格式属性。 DDL根本无法创建超链接字段,附件字段或复杂数据类型。
最终,您在DAO或ADO下执行DDL查询。对于DAO,请使用:
dbEngine( 0 )( 0 )。执行strSql,dbFailOnError
对于ADO,请使用:
CurrentProject.Connection.Execute strSql
仅在ADO下支持JET 4(Access 2000及更高版本)的某些功能。如果将SQL语句粘贴到Access中的查询设计器中,这些查询将失败,因为Access界面使用DAO。
一个DDL真的很有用的情况是更改a字段的数据类型或大小。您不能在DAO或ADOX中执行此操作,因此DDL是您唯一的实用方法(除了将所有内容复制到另一个字段并删除旧字段。)除此之外,Access开发人员不经常使用DDL。
另外,您也可以创建没有Field1
的表,然后尝试在DDL查询中添加列:
ALTER 表 Aa_News ADD COLUMN Field1 DECIMAL ( 10 , 2 );
据我了解,在某些情况下它无法工作。
另一种方式是使用
1)DAO:
< a href =http://stackoverflow.com/questions/16292960/is-it-possible-to-change-the-double-column-decimal-size> http://stackoverflow.com/questions/16292960/is - 它-可能叔o-change-the-column-decimal-size [ ^ ]
或
2)ADODB命令:
使用C#和ASp.net中的Adodb.Command.Execute方法 [ ^ ]
[/ EDIT]
Good morning everyone
I am attempting to create an accdb table with the following code :
Private Sub CreateTable(TbleName)
cn.ConnectionString = "Provider=" & cp & " Data Source=" & tss_DB.Text & ";Jet OLEDB:Database Password=Password;"
cn.Open()
cmd.Connection = cn
cmd.CommandText = "CREATE Table Aa_News (ID Counter, Field1 Double)"
cmd.ExecuteNonQuery()
cn.Close()
End Sub
This does successfully create the table but Field1 has the following properties :
Field Size : Double
Format :
Decimal Places : Auto
Input Mask :
Caption :
Default Value :
Validation Rule:
Validation Text:
Required : No
Indexed : No
Smart Tags :
Text Align : General
I need it to be it to be :
Field Size : Double
Format : Fixed
Decimal Places : 3
Input Mask :
Caption :
Default Value :
Validation Rule:
Validation Text:
Required : Yes
Indexed : No
Smart Tags :
Text Align : General
Though I have looked, I can only find setting the TEXT type field size.
Could anyone please advise me how I specify properties for different Data Types but specifically DECIMAL.
If I use
CREATE Table Aa_News (ID Counter,Field1 double(Fixed,3) )
I get a syntax error.
Your assistance greatly appreciated
Darrell
Instead:
CREATE Table Aa_News (ID Counter,Field1 double(Fixed,3) )
try:
CREATE Table Aa_News (ID Counter,Field1 double(10,3) )
or
CREATE Table Aa_News (ID Counter,Field1 DECIMAL(10,3) )
[EDIT]
It's strange, but using VBA and MS ADO 2.8 Library below code executes without errors:
CurrentProject.Connection.Execute "CREATE TABLE AAA (ID COUNTER, Field1 DECIMAL(10,3))"
So, probably, it's not possible to define the size and decimal places for field in DDL query using .NET drivers (Jet OLEDB). Please, read this: Allen Browne - MS Access Tips: DDL Code Examples[^]
Allen Browne wrote:While DDL is important in some larger databases, it is of limited use in Access. You can create a Text field, but you cannot set the Allow Zero Length property to No, so any query criteria must test for both Nulls and zero-length strings. You can create a Yes/No field, but you get a text box, not a check box, since you cannot set the Display Control property with DDL. You can create a Date/Time field, but you cannot set the Format property. DDL cannot create Hyperlink fields, Attachment fields, or the complex data types at all.
Ultimately, you execute your DDL query under DAO or ADO. For DAO, use:
dbEngine(0)(0).Execute strSql, dbFailOnError
For ADO, use:
CurrentProject.Connection.Execute strSql
Some features of JET 4 (Access 2000 and later) are supported under ADO only. These queries fail if you paste the SQL statement into the query designer in Access, since the Access interface uses DAO.
One case where DDL is really useful it to change a field's data type or size. You cannot do this in DAO or ADOX, so DDL is your the only practical approach (other than copying everything to another field and deleting the old one.) Other than that, Access developers use DDL infrequently.
Also, alternatively, you can create table withoutField1
and then try to add column in DDL query:
ALTER TABLE Aa_News ADD COLUMN Field1 DECIMAL(10,2);
As per i understand, it could not work in some cases.
Another way is to use
1) DAO:
http://stackoverflow.com/questions/16292960/is-it-possible-to-change-the-double-column-decimal-size[^]
or
2) ADODB command:
Using Adodb.Command.Execute Method in C# and ASp.net[^]
[/EDIT]
这篇关于创建具有小数位的MsAccess(accdb)表数据类型Double的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!