sql server: function gettablename(byref cbo as combox) as boolean dim rs as new adorecordset dim strrs as string strrs="select name from sysobjects where xtype=" & "'" & "u" & "'" rs.open strrs,YourActiveConnection do while not rs.eof if not rs.eof then cbo.additem rs.fields("name")
end if rs.movenext loop end function
'---------------------------------------------------------------------------- ' 'Author:lihonggen0 'Date:2003-6-19 '功能:获取access库中表的个数及表的名称 '用ado怎样实现 '工程--->引用--->Microsoft ActiveX Data Object 2.x(版本号) '---------------------------------------------------------------------------- Private Sub Form_Load() Dim adoCN As New ADODB.Connection '定义数据库的连接 Dim strCnn As New ADODB.Recordset Dim I As Integer str1 = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\Northwind.MDB;Persist Security Info=False" adoCN.Open str1
Set rstSchema = adoCN.OpenSchema(adSchemaTables)
Do Until rstSchema.EOF If rstSchema!TABLE_TYPE = "TABLE" Then out = out & "Table name: " & _ rstSchema!TABLE_NAME & vbCr & _ "Table type: " & rstSchema!TABLE_TYPE & vbCr I = I + 1 End If rstSchema.MoveNext Loop MsgBox I rstSchema.Close
adoCN.Close Debug.Print out End Subhttp://expert.csdn.net/Expert/FAQ/FAQ_Index.asp?id=8159
SQL SERVER:select name from sysobjects where xtype='u'
SQL Server中没有相应的存储过程么!
Dim cn As New ADODB.Connection If cn.State = adStateOpen Then cn.Close
Do Until rs.EOF If Trim(rs!TABLE_TYPE) = "TABLE" Then lstTable1.AddItem Trim(rs!TABLE_NAME) rs.MoveNext Loop
同意~select name from sysobjects where type = 'u'这样的~
Set resRADO = conRADO.OpenSchema(adSchemaTables) combo1.Clear Do Until resRADO.EOF If resRADO!TABLE_TYPE = "TABLE" Then combo1.AddItem resRADO!TABLE_NAME End If resRADO.MoveNext Loop resRADO.Close
adoCN.Open strCnn
Set rstSchema = adoCN.OpenSchema(adSchemaTables)
Do Until rstSchema.EOF
If rstSchema!TABLE_TYPE = "TABLE" Then
cob.AddItem rstSchema!TABLE_NAME
End If
rstSchema.MoveNext
Loop
function gettablename(byref cbo as combox) as boolean
dim rs as new adorecordset
dim strrs as string
strrs="select name from sysobjects where xtype=" & "'" & "u" & "'"
rs.open strrs,YourActiveConnection
do while not rs.eof
if not rs.eof then
cbo.additem rs.fields("name")
end if
rs.movenext
loop
end function
'
'Author:lihonggen0
'Date:2003-6-19
'功能:获取access库中表的个数及表的名称
'用ado怎样实现
'工程--->引用--->Microsoft ActiveX Data Object 2.x(版本号)
'----------------------------------------------------------------------------
Private Sub Form_Load()
Dim adoCN As New ADODB.Connection '定义数据库的连接
Dim strCnn As New ADODB.Recordset
Dim I As Integer
str1 = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\Northwind.MDB;Persist Security Info=False"
adoCN.Open str1
Set rstSchema = adoCN.OpenSchema(adSchemaTables)
Do Until rstSchema.EOF
If rstSchema!TABLE_TYPE = "TABLE" Then
out = out & "Table name: " & _
rstSchema!TABLE_NAME & vbCr & _
"Table type: " & rstSchema!TABLE_TYPE & vbCr
I = I + 1
End If
rstSchema.MoveNext
Loop
MsgBox I
rstSchema.Close
adoCN.Close
Debug.Print out
End Subhttp://expert.csdn.net/Expert/FAQ/FAQ_Index.asp?id=8159
cn.ConnectionString = "dsn=" & cboDSN1.Text & ";uid=" & txtUID1.Text & ";pwd=" & txtPWD1.Text
cn1.Open
Set rs = cn.OpenSchema(adSchemaTables)
lstTable1.Clear
lblStatus1.Caption = "数据源连接成功,正在检索数据表..."
DoEvents
Do Until rs.EOF
If Trim(rs!TABLE_TYPE) = "TABLE" Then lstTable1.AddItem Trim(rs!TABLE_NAME)
rs.MoveNext
Loop
combo1.Clear
Do Until resRADO.EOF
If resRADO!TABLE_TYPE = "TABLE" Then
combo1.AddItem resRADO!TABLE_NAME
End If
resRADO.MoveNext
Loop
resRADO.Close