如何使用combo控件
2个回答
2013-08-23
展开全部
一:新建一个模块,保存以下代码.注意修改数据库路径/名/密码/
Public Conn As New ADODB.Connection
Public Rs As New ADODB.Recordset
Public Sql As String
Public UserName As String
Public UserLimit As Integer
'==================
'连接数据库
'==================
Public Function DB_Link()
On Error Resume Next
Dim CnStr As String
Dim DBPath As String, DBName As String
Dim DBUser As String, DBPsw As String
DBPath = App.Path & "\" '数据库地址
DBName = DATABASE_NAME '数据库文件名
DBPsw = DATABASE_PASSWORD '数据库密码
CnStr = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data source =" & DBPath & DBName & "; Jet OLEDB:Database Password=" & DBPsw
Conn.CursorLocation = adUseClient '必须设置客户端游标方式
Conn.Open CnStr
End Function
'====================
'断开数据库
'====================
Public Function DB_Close()
On Error Resume Next
Rs.Close
Set Rs = Nothing
Conn.Close
Set Conn = Nothing
End Function
二:窗体代码.
private sub form_load()
db_link
sql = "select * from 保存项目名称的那个表名"
set rs =conn.execute(sql)
do until rs.eof
combo1.additem rs("项目名称所在列名")
rs.movenext
db_close
end sub
以上是添加到combo1的代码...
Public Conn As New ADODB.Connection
Public Rs As New ADODB.Recordset
Public Sql As String
Public UserName As String
Public UserLimit As Integer
'==================
'连接数据库
'==================
Public Function DB_Link()
On Error Resume Next
Dim CnStr As String
Dim DBPath As String, DBName As String
Dim DBUser As String, DBPsw As String
DBPath = App.Path & "\" '数据库地址
DBName = DATABASE_NAME '数据库文件名
DBPsw = DATABASE_PASSWORD '数据库密码
CnStr = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data source =" & DBPath & DBName & "; Jet OLEDB:Database Password=" & DBPsw
Conn.CursorLocation = adUseClient '必须设置客户端游标方式
Conn.Open CnStr
End Function
'====================
'断开数据库
'====================
Public Function DB_Close()
On Error Resume Next
Rs.Close
Set Rs = Nothing
Conn.Close
Set Conn = Nothing
End Function
二:窗体代码.
private sub form_load()
db_link
sql = "select * from 保存项目名称的那个表名"
set rs =conn.execute(sql)
do until rs.eof
combo1.additem rs("项目名称所在列名")
rs.movenext
db_close
end sub
以上是添加到combo1的代码...
AiPPT
2024-09-19 广告
2024-09-19 广告
随着AI技术的飞速发展,如今市面上涌现了许多实用易操作的AI生成工具1、简介:AiPPT: 这款AI工具智能理解用户输入的主题,提供“AI智能生成”和“导入本地大纲”的选项,生成的PPT内容丰富多样,可自由编辑和添加元素,图表类型包括柱状图...
点击进入详情页
本回答由AiPPT提供
2013-08-23
展开全部
不知道你是否用的是VB,如果是VB的话,在窗体加载事件中增加代码即可,代码如下:Private Sub Form_Load()
Combo1.Text = "1"
Combo1.AddItem "1"
Combo1.AddItem "2"
Combo1.AddItem "3"
Combo1.AddItem "4"
Combo1.AddItem "5"
End Sub
Combo1.Text = "1"
Combo1.AddItem "1"
Combo1.AddItem "2"
Combo1.AddItem "3"
Combo1.AddItem "4"
Combo1.AddItem "5"
End Sub
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询