如何在vb中判断一个数据表是否存在?
可以if exsit table_name then do 吗? 问题点数:0、回复次数:6Top
1 楼lxqlogo0(群子)回复于 2003-08-04 09:10:30 得分 0
确定sql中的表的个数
Dim objcon As New ADODB.Connection
Dim objrs As New ADODB.Recordset
objcon.Open "Provider=sqloledb.1;user id=sa;password=csm@csm;Initial Catalog=xiazaijilu;Data Source="
objrs.Open "select * from sysobjects where xtype='u' ", objcon, 3, 1Top
2 楼alicky(周松)回复于 2003-08-04 09:11:05 得分 0
http://expert.csdn.net/Expert/topic/1876/1876180.xml?temp=.2484705Top
3 楼lxqlogo0(群子)回复于 2003-08-04 09:13:16 得分 0
objrs.Open "select * from sysobjects where name='table name'",conn,3,1
If objRS.EOF Then
msgbox "Not Exsit"
End If
Top
4 楼gpo2002(永吹不休)回复于 2003-08-04 09:15:36 得分 0
DAO
Dim d As Database
Dim t As TableDef
.....
For Each t In d.TableDefs
Debug.Print t.Name
NextTop
5 楼ch21st(www.blanksoft.com)回复于 2003-08-04 09:38:20 得分 0
Dim rsSchema As New ADODB.Recordset
Dim fld As ADODB.Field
Dim rCriteria As Variant
Dim cn As New ADODB.Connection
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; " & _
"Data Source=" & strDataSource
cn.Mode = adModeReadWrite
cn.Open
rCriteria = Array(Empty, Empty, Empty, "Table")
Set rsSchema = cn.OpenSchema(adSchemaTables, rCriteria)
Debug.Print "Recordcount: " & rsSchema.RecordCount
While Not rsSchema.EOF
Debug.Print "==================================================="
For Each fld In rsSchema.Fields
If (fld.Name = "TABLE_NAME" And Mid(Trim(UCase(fld.Value)), 1, 4) <> "MSYS") Then
List1.AddItem fld.Value
End If
Next
rsSchema.MoveNext
Wend
表名列表
善后处理略Top
6 楼lihonggen0(李洪根,MS MVP,标准答案来了)回复于 2003-08-04 12:38:10 得分 0
'*********************************************************
'* 名称:TableExists
'* 功能:判断表是否存在(表名)
'* 用法:TableExists(表名) adoCN是一个SQL的连接
'*********************************************************
Public Function TableExists(findTable As String) As Boolean
Dim rstSchema As New ADODB.Recordset
Set rstSchema = adoCN.OpenSchema(adSchemaTables)
rstSchema.Find "TABLE_NAME='" & findTable & "'"
If rstSchema.EOF Then
TableExists = False
Else
TableExists = True
End If
rstSchema.Close
End Function
Top




