回复人: supergreenbean(超级绿豆-梅雨来,霉了绿豆,红了杨梅) ( ) 信誉:116 2004-6-19 20:45:09 得分:0 引用ADOX
类似这样:
Option ExplicitPublic g_oCnn As Connection
Public g_oCat As Catalog
Public g_oRst As Recordset
Public Const DBNAME_PLACE_HODLER As String = "<DBPATH>"
Public Const DATABASE_CONNECTION_STRING As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & DBNAME_PLACE_HODLERPublic Function GetConnStr(ByVal sDBName As String) As String
GetConnStr = DATABASE_CONNECTION_STRING
GetConnStr = Replace(GetConnStr, DBNAME_PLACE_HODLER, sDBName)
End FunctionPublic Function CreateDB(ByVal sDBName As String) As Boolean
On Error GoTo Error_Handler
Dim sCnnStr As String
Set g_oCat = New ADOX.Catalog
sCnnStr = GetConnStr(sDBName)
g_oCat.Create sCnnStr
CreateDB = True
Exit Function
Error_Handler:
End FunctionPublic Function CreateTable(ByVal sTableName As String) As Recordset
On Error GoTo Error_Handler
If g_oCat Is Nothing Then Exit Function
Dim oTable As Table
Set oTable = New Table
With oTable
.Name = sTableName
Set .ParentCatalog = g_oCat
.Columns.Append "id", adInteger
.Columns("id").Properties("AutoIncrement") = True
.Keys.Append "colid", adKeyPrimary, "id"
.Columns.Append "name", adVarWChar, 50
.Columns.Append "value", adVarWChar, 50
.Columns("value").Attributes = adColNullable
End With
g_oCat.Tables.Append oTable
Set CreateTable = New ADODB.Recordset
With CreateTable
.Open sTableName, g_oCat.ActiveConnection, adOpenDynamic, adLockOptimistic
End With
Set oTable = Nothing
Exit Function
Error_Handler:
Set oTable = Nothing
Set CreateTable = Nothing
End Function
类似这样:
Option ExplicitPublic g_oCnn As Connection
Public g_oCat As Catalog
Public g_oRst As Recordset
Public Const DBNAME_PLACE_HODLER As String = "<DBPATH>"
Public Const DATABASE_CONNECTION_STRING As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & DBNAME_PLACE_HODLERPublic Function GetConnStr(ByVal sDBName As String) As String
GetConnStr = DATABASE_CONNECTION_STRING
GetConnStr = Replace(GetConnStr, DBNAME_PLACE_HODLER, sDBName)
End FunctionPublic Function CreateDB(ByVal sDBName As String) As Boolean
On Error GoTo Error_Handler
Dim sCnnStr As String
Set g_oCat = New ADOX.Catalog
sCnnStr = GetConnStr(sDBName)
g_oCat.Create sCnnStr
CreateDB = True
Exit Function
Error_Handler:
End FunctionPublic Function CreateTable(ByVal sTableName As String) As Recordset
On Error GoTo Error_Handler
If g_oCat Is Nothing Then Exit Function
Dim oTable As Table
Set oTable = New Table
With oTable
.Name = sTableName
Set .ParentCatalog = g_oCat
.Columns.Append "id", adInteger
.Columns("id").Properties("AutoIncrement") = True
.Keys.Append "colid", adKeyPrimary, "id"
.Columns.Append "name", adVarWChar, 50
.Columns.Append "value", adVarWChar, 50
.Columns("value").Attributes = adColNullable
End With
g_oCat.Tables.Append oTable
Set CreateTable = New ADODB.Recordset
With CreateTable
.Open sTableName, g_oCat.ActiveConnection, adOpenDynamic, adLockOptimistic
End With
Set oTable = Nothing
Exit Function
Error_Handler:
Set oTable = Nothing
Set CreateTable = Nothing
End Function
解决方案 »
- 各位大侠路过看看啊!!VB的
- 求助 我在用Setfiletime这个函数时总显示“编译错误: 用户定义类型未定义”为什么呢?
- 一个奇怪的问题,集思广益
- 请教fpspread做表格编辑的问题
- 100分求救
- 请问,如何判断屏幕分辨率来 判断加载 1024*768 或者 800*600 的图片呢。
- 求助:怎样得到一个地图对象Bounds内某指定图层的所有图元 ?
- 怎么用VB+ADO 来获得MYSQL数据库中的所有库名
- 关于一个自定义数据字典查询的问题,求解好算法!!!!!!
- 如何控制在文本框中只允许输入数字或+,-号,最好不要在keydown或change中编代码
- 救命:关于随机文件的读取!!!!不得其解!在线解决马上结贴!
- 新手问题
朋友,能不能把你的代码发给我,拜托了
因为时间紧,没学过vb,所以请大家帮忙
///
牽涉倒分數,過分著,都會被刪,這次先警告!
请留下联系方式
不好意思,很久没来csdn了,忘记这个规则了
///
沒事,下次注意吧,這樣的帖以後不要往基礎版面放。呵呵~~