我用ADO向ACCESS数据库里建的表,添加的字段,但我还想把字段说明和表说明也添加进去。

aassdd 2004-09-29 01:48:51
比如我的字段名是ID,字段类型是自动编号,字段说明是‘序号’,我想把‘序号’用ADO添到ACCESS设计视图的说明里。。这个问题困扰我很长时间。
...全文
295 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
Zerosir 2004-10-02
  • 打赏
  • 举报
回复
我以前写的一个示例,看看是否有用(要引用AdoX):
Private Sub CreateTables()
On Error GoTo ErrTrap
Dim TBL As adox.Table

' ===[创建一个表:'BE_Version']===
Set TBL = New adox.Table
Set TBL.ParentCatalog = cat
TBL.Name = "BE_Version"

TBL.Columns.Append "ID", adInteger, 0
TBL.Columns("ID").Properties("AutoIncrement") = True
TBL.Columns("ID").Properties("NullAble") = True
TBL.Columns("ID").Properties("Description") = "说明文字在这里"

TBL.Keys.Append "ID", adKeyPrimary, "ID"

TBL.Columns.Append "Version", adVarWChar, 255
TBL.Columns("Version").Properties("NullAble") = True
cat.Tables.Append TBL
Set TBL = Nothing

Exit Sub
ErrTrap:
MsgBox Err.Number & " / " & Err.Description, , "Error In CreateTables"
Exit Sub
Resume
End sub
xxfeiyu 2004-10-01
  • 打赏
  • 举报
回复
ADOX能行
aassdd 2004-10-01
  • 打赏
  • 举报
回复
Up
aassdd 2004-09-30
  • 打赏
  • 举报
回复
高手!斑竹们!有时间能来讨论一下用 ADO或ACCESS的SQL语句添加说明~~~~~~这个问题实在是困扰我很长时间了。
aassdd 2004-09-30
  • 打赏
  • 举报
回复
to wshlxvb(酒鬼英明) :你说的属性好像是DAO的,或ADOX的吧!
可能我没说明白,我是用VB做个对ACCESS数据库的维护程序,要对字段添加说明,用ADO实在是没办法了,哪位要是有用DAO添加说明即.Description的属性,发到我的信箱也行啊!立刻放分。谢了。
zhangruijilin@yahoo.com.cn
wshlxvb 2004-09-30
  • 打赏
  • 举报
回复
楼上老大你说什么啊?没看明白.Description属性足够了.
libingao 2004-09-30
  • 打赏
  • 举报
回复
用 ACCESS 作为多用户的服务器数据库,需要引入 事务,负责会容易产生数据不完整!
以下例子是用 ADO 连接 SQL SERVER 和 ACCESS 数据库的例子:
Private Sub Command1_Click()
On Error GoTo errorHandler

Dim adoCnn As New ADODB.Connection
Dim adoRst As New ADODB.Recordset
Dim BeginTransBol As Boolean '是否已开始一个 ado 事务
Dim CnnStr As String
Dim cSql As String

BeginTransBol = False
'CnnStr = "Provider=SQLOLEDB.1;Persist Security Info=True; Initial Catalog=[数据库名];Data Source=[服务器名]; User ID=sa;Password=;" '基于 用户名和密码的访问
'CnnStr = "Provider=SQLOLEDB.1;Persist Security Info=False;Initial Catalog=[数据库名];Data Source=[服务器名]; Integrated Security=SSPI;" '基于 windows 集成的安全访问
CnnStr = "provider=Microsoft.Jet.OLEDB.4.0;Data source =" + [Access97、Access2000 数据库路径及名称] + " ;Persist Security Info=False;Jet OLEDB:Database Password=" + [数据库密码] '访问 Access 数据库
With adoCnn
If .State = adStateOpen Then .Close
.ConnectionString = CnnStr
.Open
If .State = adStateOpen Then
' 数据库打开成功
' 开始一个事物,设置事务的隔离层为 adXactReadCommitted

.IsolationLevel = adXactReadUncommitted ' adXactReadCommitted
.BeginTrans '开始一个事务
BeginTransBol = True

cSql = "DELETE * FROM report_head1"
.Execute cSql, , adCmdText + adExecuteNoRecords '参数 adExecuteNoRecords 表示不返回任何记录集,可提高执行速度

cSql = "SELECT * FROM report_head1 WHERE 编号 = " + Text1.Text
With adoRst
If .State = adStateOpen Then .Close
.ActiveConnection = adoCnn
.CursorLocation = adUseClient
.LockType = adLockBatchOptimistic
.CursorType = adOpenStatic
' 当查询为多个表的联合查询同时更新只对其中的一个表进行时,可用下面的语句显式指定要更新的表名
.Properties("Unique Table") = "report_head1"
.Source = cSql
.Open
' Disconnect the recordset 切断记录集
Set .ActiveConnection = Nothing

If .RecordCount <> 0 Then
MsgBox "编号已经存在,请重新输入!", vbInformation, "录入重复. . ."
Text1.SetFocus
Else
.AddNew
'开始添加记录
.Fields("编号").Value = Text1.Text

'...

' Reconnect and update Access or SQL Server
.ActiveConnection = adoCnn
.UpdateBatch
End If
End With
.CommitTrans '提交当前事务
BeginTransBol = False
Else
' 数据库打开失败
' ...
End If

End With
Exit Sub
errorHandler:
If adoCnn.State = adStateOpen And BeginTransBol Then adoCnn.RollbackTrans '有错误发生,回滚当前事务
MsgBox Err.Description + "(错误号:" + CStr(Err.Number) + ")", vbCritical, "出错拉 . . ."

End Sub

Private Sub print_kuozhan_Click()
'按扩展方式进行打印
On Error GoTo errorHandler
Call SetCursor(LoadCursor(0, 32514))

Dim Idnamestr As String
Dim cSql As String
Dim strYear As String '系统时间的年月日
Dim strtime As String '系统时间的时分
Dim str As String '包含年月日和时分的系统时间
Dim BeginTransBol As Boolean '是否已开始一个 ado 事务

With adoCnn
If .State <> adStateOpen Then
If Not vConnection_ADO(adoCnn, MainDataName, , PasswordM) Then
MsgBox "ADO 没有正常连接上数据库,请关闭当前窗体再打开一次试试。" + vbCrLf + "如果还是报同样的错误,请与系统管理员联系!", vbCritical, MsgBoxTitle
Exit Sub
End If
End If

' 开始一个事物,设置事务的隔离层为 adXactReadCommitted

.IsolationLevel = adXactReadUncommitted ' adXactReadCommitted
.BeginTrans
BeginTransBol = True

cSql = "DELETE * FROM report_head1"
.Execute cSql, , adCmdText + adExecuteNoRecords '参数 adExecuteNoRecords 表示不返回任何记录集,可提高执行速度

cSql = "SELECT * FROM report_head1"
With adoRst
If .State = adStateOpen Then .Close
.ActiveConnection = adoCnn
.CursorLocation = adUseClient
.LockType = adLockBatchOptimistic
.CursorType = adOpenStatic
' 当查询为多个表的联合查询同时更新只对其中的一个表进行时,可用下面的语句显式指定要更新的表名
.Properties("Unique Table") = "report_head1"
.Source = cSql

.Open
' Disconnect the recordset 切断记录集
Set .ActiveConnection = Nothing

.AddNew
.Fields("companyname").Value = p_companyname
.Fields("typename") = "库存查询报表"

strYear = Format(Date, "YYYYMMDD")
strtime = Format(Time, "HHMM")
str = Left(strYear, 4) + "年" + Mid(strYear, 5, 2) + "月" + Mid(strYear, 7, 2) + "日 " + Mid(strtime, 1, 2) + ":" + Mid(strtime, 3, 2)

.Fields("memo2").Value = "[目前全部理论库存] "
.Fields("memo1").Value = "产品尺码明细"
.Fields("Date").Value = "打印日期:" + str

' Reconnect and update Access or SQL Server
.ActiveConnection = adoCnn
.UpdateBatch

End With
.CommitTrans
BeginTransBol = False

End With
Exit Sub

errorHandler:
If adoCnn.State = adStateOpen And BeginTransBol Then adoCnn.RollbackTrans
MsgBox "打印过程中出现错误,因为:" + err.Description + "(错误号:" + CStr(err.number) + ")", vbCritical, MsgBoxTitle

End Sub
libingao 2004-09-29
  • 打赏
  • 举报
回复
要是用DAO和ADO同时连一个ACCESS数据库,原则上程序能够顺利执行;但由于可能出现 多用户并发的去打开同一个数据库表,这样很容易损坏数据库,ACCESS数据库只适用于单机版的小型软件,对于网络版的软件建议最好采用 SQL Server 数据库。

我有一个进销存软件,用的是 ACCESS97 数据库,里面用到了 DAO 和 ADO,而且客户端也有五六个,问题是:偶尔会出现当其中一个客户端机子非法退出时,容易损坏数据库,我现在的解决办法是:自动去修复压缩一次数据库。你也知道 ACCESS 数据库用时间长了,所占的体积很大,其实里面大多是垃圾,需要定时压缩数据库。
aassdd 2004-09-29
  • 打赏
  • 举报
回复
其实~不添也无所谓的。最多多开几个窗口呵呵~~
要是用DAO和ADO同时连一个ACCESS数据库,能有什么影响吗!~
RUKYO 2004-09-29
  • 打赏
  • 举报
回复
据Access中的帮助提示来看是不能用ado方式来实现的,其实也无所谓啊,引用一下dao对象写几行代码而已嘛:)
aassdd 2004-09-29
  • 打赏
  • 举报
回复
谢谢楼上的兄台,难道只能用DAO吗?或者就没有SQL语句能添加,我一直觉得ADO对数据库的操作是全能的。我在CSDN上也搜了很长时间好像没有这方面的。能否弥补这个空白啊!!~~~~~~~:)
RUKYO 2004-09-29
  • 打赏
  • 举报
回复
MSDN的例子:

CreateProperty Method Example

This example tries to set the value of a user-defined property. If the property doesn't exist, it uses the CreateProperty method to create and set the value of the new property. The SetProperty procedure is required for this procedure to run.

Sub CreatePropertyX()

Dim dbsNorthwind As Database
Dim prpLoop As Property

Set dbsNorthwind = OpenDatabase("Northwind.mdb")

' Set the Archive property to True.
SetProperty dbsNorthwind, "Archive", True

With dbsNorthwind
Debug.Print "Properties of " & .Name

' Enumerate Properties collection of the Northwind
' database.
For Each prpLoop In .Properties
If prpLoop <> "" Then Debug.Print " " & _
prpLoop.Name & " = " & prpLoop
Next prpLoop

' Delete the new property since this is a
' demonstration.
.Properties.Delete "Archive"

.Close
End With

End Sub

Sub SetProperty(dbsTemp As Database, strName As String, _
booTemp As Boolean)

Dim prpNew As Property
Dim errLoop As Error

' Attempt to set the specified property.
On Error GoTo Err_Property
dbsTemp.Properties("strName") = booTemp
On Error GoTo 0

Exit Sub

Err_Property:

' Error 3270 means that the property was not found.
If DBEngine.Errors(0).Number = 3270 Then
' Create property, set its value, and append it to the
' Properties collection.
Set prpNew = dbsTemp.CreateProperty(strName, _
dbBoolean, booTemp)
dbsTemp.Properties.Append prpNew
Resume Next
Else
' If different error has occurred, display message.
For Each errLoop In DBEngine.Errors
MsgBox "Error number: " & errLoop.Number & vbCr & _
errLoop.Description
Next errLoop
End
End If

End Sub
RUKYO 2004-09-29
  • 打赏
  • 举报
回复
Description 属性


使用 Description(说明)属性不仅可以提供有关包含在“数据库”窗口中的对象信息,还可以提供有关单个表或查询字段的信息。

设置

对于一个数据库,请单击“视图”菜单上的“属性”命令,并在“说明”框中输入说明文本。对于表或查询,也可以在表或查询的属性表中输入说明文本。当在“视图”菜单上单击“详细信息”命令时,对象的说明将在“数据库”窗口中紧挨着对象名称的地方显示。

对于单个表或查询字段,在表“设计”视图的上方窗格中,或者在“查询”窗口的“字段属性”属性表中都可以输入字段的说明文字。字符长度不超过 255 个字符。

在 Visual Basic 中,如果在 Microsoft Access 项目 (.adp) 内是首次设置此属性,必须通过 Add 方法创建应用程序定义的属性。在 Microsoft Access 数据库 (.mdb) 中,必须使用 DAO CreateProperty 方法来创建应用程序定义的属性。

说明

在“数据库”窗口的“详细信息”视图中“说明”列将显示对象的说明。

如果通过从字段列表中拖动字段来创建控件,Microsoft Access 会将该字段的 Description 属性值复制到控件的 StatusBarText 属性值中。

注意 对于一个链接表,Microsoft Access 将在 Description 属性中显示其连接信息。
vbanddelphi 2004-09-29
  • 打赏
  • 举报
回复
我不知道有没有理解错你的问题!我觉得不难,在VB里有个数据窗口向导,你自己做一个看看就明白了!
aassdd 2004-09-29
  • 打赏
  • 举报
回复
我记得用ADO连ACCESS时,可以给表添加说明了。就是description属性,现在忘了。

1,216

社区成员

发帖
与我相关
我的任务
社区描述
VB 数据库(包含打印,安装,报表)
社区管理员
  • 数据库(包含打印,安装,报表)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧