有关VB的问题 车型及选中的长宽高都在ACCESS数据库中,我想在车型的下拉菜单中选中一值 对应的长宽高即显
四个框都不用输入功能只要车型下拉菜单选中一个长宽高就可以读取对应数据库值拜托各位大虾了在线等回答的完美会追分的~...
四个框都不用输入功能 只要车型下拉菜单选中一个 长宽高就可以读取对应数据库值
拜托各位大虾了 在线等 回答的完美会追分的~ 展开
拜托各位大虾了 在线等 回答的完美会追分的~ 展开
展开全部
我用的是动态数组,所以要动态申请数组的维数需要UBound 函数;
UBound 函数
返回一个 Long 型数据,其值为指定的数组维可用的最大下标
可以使用一下类似的语句
Set cn = CreateObject("ADODB.Connection")
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=True;Data Source=d:\chexing.mdb"
cn.Open
str1 = "select id,chexing,chang,kuan,gao from chexing "
Set rs = CreateObject("adodb.recordset")
rs.Open str1, cn, 1, 1
调试程序如下(适当改一下你的表名,键值等)
'access 数据表表名:chexing
'结构id、chexing、chang、kuan、gao
Dim id() As Long
Dim chang() As Long
Dim kuan() As Long
Dim gao() As Long
Private Sub Combo1_Click()
Text1.Text = chang(Combo1.ListIndex)
Text2.Text = kuan(Combo1.ListIndex)
Text3.Text = gao(Combo1.ListIndex)
End Sub
Private Sub Form_Load()
ReDim id(0)
ReDim chang(0)
ReDim kuan(0)
ReDim gao(0)
Combo1.Clear
Set cn = CreateObject("ADODB.Connection")
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=True;Data Source=d:\chexing.mdb"
cn.Open
str1 = "select id,chexing,chang,kuan,gao from chexing "
'db = "d:\chexing.mdb"
'connstr = "DBQ=" + db + ";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)}"
' Set conn = CreateObject("ADODB.Connection")
'conn.Open connstr
'websql = "select * from chexing order by id"
Set rs = CreateObject("adodb.recordset")
rs.Open str1, cn, 1, 1
If rs.EOF And rs.BOF Then
Else
Do While Not rs.EOF
Combo1.AddItem rs("chexing")
id(UBound(id)) = rs("id")
ReDim Preserve id(UBound(id) + 1)
chang(UBound(chang)) = rs("chang")
ReDim Preserve chang(UBound(chang) + 1)
kuan(UBound(kuan)) = rs("kuan")
ReDim Preserve kuan(UBound(kuan) + 1)
gao(UBound(gao)) = rs("gao")
ReDim Preserve gao(UBound(gao) + 1)
rs.MoveNext
Loop
End If
rs.Close
Set rs = Nothing
Set conn = Nothing
Combo1.ListIndex = 0
End Sub
UBound 函数
返回一个 Long 型数据,其值为指定的数组维可用的最大下标
可以使用一下类似的语句
Set cn = CreateObject("ADODB.Connection")
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=True;Data Source=d:\chexing.mdb"
cn.Open
str1 = "select id,chexing,chang,kuan,gao from chexing "
Set rs = CreateObject("adodb.recordset")
rs.Open str1, cn, 1, 1
调试程序如下(适当改一下你的表名,键值等)
'access 数据表表名:chexing
'结构id、chexing、chang、kuan、gao
Dim id() As Long
Dim chang() As Long
Dim kuan() As Long
Dim gao() As Long
Private Sub Combo1_Click()
Text1.Text = chang(Combo1.ListIndex)
Text2.Text = kuan(Combo1.ListIndex)
Text3.Text = gao(Combo1.ListIndex)
End Sub
Private Sub Form_Load()
ReDim id(0)
ReDim chang(0)
ReDim kuan(0)
ReDim gao(0)
Combo1.Clear
Set cn = CreateObject("ADODB.Connection")
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=True;Data Source=d:\chexing.mdb"
cn.Open
str1 = "select id,chexing,chang,kuan,gao from chexing "
'db = "d:\chexing.mdb"
'connstr = "DBQ=" + db + ";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)}"
' Set conn = CreateObject("ADODB.Connection")
'conn.Open connstr
'websql = "select * from chexing order by id"
Set rs = CreateObject("adodb.recordset")
rs.Open str1, cn, 1, 1
If rs.EOF And rs.BOF Then
Else
Do While Not rs.EOF
Combo1.AddItem rs("chexing")
id(UBound(id)) = rs("id")
ReDim Preserve id(UBound(id) + 1)
chang(UBound(chang)) = rs("chang")
ReDim Preserve chang(UBound(chang) + 1)
kuan(UBound(kuan)) = rs("kuan")
ReDim Preserve kuan(UBound(kuan) + 1)
gao(UBound(gao)) = rs("gao")
ReDim Preserve gao(UBound(gao) + 1)
rs.MoveNext
Loop
End If
rs.Close
Set rs = Nothing
Set conn = Nothing
Combo1.ListIndex = 0
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询