VB用LISTBOX列出数据库的所有表名
我有一个SQL数据库DATA,成功连接到它后。我想用一个LISTBOX列出DATA里面的所有表的名字。请问可以怎样做到?...
我有一个SQL数据库DATA,成功连接到它后。
我想用一个LISTBOX列出DATA里面的所有表的名字。请问可以怎样做到? 展开
我想用一个LISTBOX列出DATA里面的所有表的名字。请问可以怎样做到? 展开
5个回答
展开全部
dim cn as adodb.connection
dim rs as adodb.recordset
dim tsql as string
dim i as integer
set cn=new adodb.connection
cn.open "driver={sql server};server=servername;database=DATA;uid=sa;pwd=password"
tsql="select name from sysobjects where type='U'"
set rs=new adodb.recordset
rs.open tsql,cn,4,2
if rs.recordcount>0 then
list1.clear
rs.movefirst
for i=0 to rs.recordcount-1
list1.add rs.fields("name"),i
rs.movenext
next i
end if
set rs=nothing
set cn=nothing
dim rs as adodb.recordset
dim tsql as string
dim i as integer
set cn=new adodb.connection
cn.open "driver={sql server};server=servername;database=DATA;uid=sa;pwd=password"
tsql="select name from sysobjects where type='U'"
set rs=new adodb.recordset
rs.open tsql,cn,4,2
if rs.recordcount>0 then
list1.clear
rs.movefirst
for i=0 to rs.recordcount-1
list1.add rs.fields("name"),i
rs.movenext
next i
end if
set rs=nothing
set cn=nothing
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
dim conn as new adodb.connection
dim rs as new adodb.recordset
dim sql as string
dim i as integer
conn .open "连接字符串"
sql="select name from sysobjects where type='U'"
rs.open sql,conn,1,1
list11.clear
for i=1 to rs.recordcount
list1.add rs("name")
rs.movenext
next i
set rs=nothing
set cn=nothing
dim rs as new adodb.recordset
dim sql as string
dim i as integer
conn .open "连接字符串"
sql="select name from sysobjects where type='U'"
rs.open sql,conn,1,1
list11.clear
for i=1 to rs.recordcount
list1.add rs("name")
rs.movenext
next i
set rs=nothing
set cn=nothing
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
用以下sql语句:
select name from sysobjects where type='U'
取到结果显示在LISTBOX里面就简单了
select name from sysobjects where type='U'
取到结果显示在LISTBOX里面就简单了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Dim AdoRecordset2 As ADODB.Recordset
Private Sub Form_Load()
call Refreshdata2()
End Sub
Private Sub Refreshdata2()
Dim Rs_str As String
Set AdoRecordset2 = New ADODB.Recordset
Rs_str = "select id,name form sysobjects where type='u'"
connstr
If AdoRecordset2.State = adStateOpen Then
AdoRecordset2.Close
End If
With AdoRecordset2
Set .ActiveConnection = adoConnection
.CursorType = adOpenDynamic
.LockType = adLockOptimistic
.Open Rs_str
End With
Set DataCombo1.RowSource = AdoRecordset2
DataCombo1.BoundColumn = AdoRecordset2.Fields(0).Name
DataCombo1.ListField = AdoRecordset2.Fields(1).Name
If Not AdoRecordset2.BOF And Not AdoRecordset2.EOF Then
DataCombo1.Text = AdoRecordset2.Fields(1)
End If
End Sub
Public Sub connstr()‘连接数据库语句,此处略
……
End Sub
Private Sub Form_Load()
call Refreshdata2()
End Sub
Private Sub Refreshdata2()
Dim Rs_str As String
Set AdoRecordset2 = New ADODB.Recordset
Rs_str = "select id,name form sysobjects where type='u'"
connstr
If AdoRecordset2.State = adStateOpen Then
AdoRecordset2.Close
End If
With AdoRecordset2
Set .ActiveConnection = adoConnection
.CursorType = adOpenDynamic
.LockType = adLockOptimistic
.Open Rs_str
End With
Set DataCombo1.RowSource = AdoRecordset2
DataCombo1.BoundColumn = AdoRecordset2.Fields(0).Name
DataCombo1.ListField = AdoRecordset2.Fields(1).Name
If Not AdoRecordset2.BOF And Not AdoRecordset2.EOF Then
DataCombo1.Text = AdoRecordset2.Fields(1)
End If
End Sub
Public Sub connstr()‘连接数据库语句,此处略
……
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询