| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1779 人关注过本帖
标题:如何把COMBO1控件里的LIST一月、二月、三月、四月与DB1里的F1表、F2表、F3表 ...
只看楼主 加入收藏
purana
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:广东-广州
等 级:版主
威 望:66
帖 子:6039
专家分:0
注 册:2005-6-17
收藏
得分:0 
datagrid上显示adodc中指定的RecordSource.无论找哪一本.介绍VB数据库的.一定有讲到.不用无数的调试吧..呵呵.


我的msn: myfend@
2007-09-07 20:46
lijun337
Rank: 1
等 级:新手上路
帖 子:379
专家分:5
注 册:2006-4-12
收藏
得分:0 
最笨的办法,就是干脆建12个COMMAND控件!这最简单!
我只好用了这办法解决了问题!
2007-09-07 20:48
purana
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:广东-广州
等 级:版主
威 望:66
帖 子:6039
专家分:0
注 册:2005-6-17
收藏
得分:0 
我在8楼已经提供了类似的解决方案了.

我的msn: myfend@
2007-09-07 20:55
multiple1902
Rank: 8Rank: 8
等 级:贵宾
威 望:42
帖 子:4881
专家分:671
注 册:2007-2-9
收藏
得分:0 
以下是引用purana在2007-9-7 20:55:46的发言:
我在8楼已经提供了类似的解决方案了.

同意。

2007-09-07 21:18
lijun337
Rank: 1
等 级:新手上路
帖 子:379
专家分:5
注 册:2006-4-12
收藏
得分:0 

Option Explicit
Private conn As ADODB.Connection
Private Rst As New ADODB.Recordset
Dim arrMonth(12) As String

Private Sub Command1_Click()
Dim intListIndex As Integer
Dim strMonth As String

intListIndex = Combo1.ListIndex

strMonth = arrMonth(intListIndex)

'MsgBox strMonth

'declare rs As Recordset,con As Connection Objects
'rs.Open "SELECT xxx FROM " & strMonth ,con, ,
End Sub

Private Sub Form_Load()
Dim ConString As String
Dim i As Integer
For i = 0 To UBound(arrMonth) - 1
arrMonth(i) = "f" & (i + 1) & "表"
Combo1.AddItem arrMonth(i)
Next

ConString = "Provider=Microsoft.Jet.OleDb.4.0;Persist Security Info = False;" _
& "Data Source =" & App.Path & "\db1.mdb;Jet OleDb:"


Set conn = CreateObject("ADODB.Connection")
With conn
.ConnectionString = ConString
.Open
End With
End Sub

执行后,没有反应!!

Combo1的属性设置仍然就在List里面设定了12个月。其余未作改动!

2007-09-08 17:21
lijun337
Rank: 1
等 级:新手上路
帖 子:379
专家分:5
注 册:2006-4-12
收藏
得分:0 

改:

Option Explicit
Private conn As ADODB.Connection
Private Rst As New ADODB.Recordset
Dim arrMonth(12) As String

Private Sub Command1_Change()
Dim intListIndex As Integer
Dim strMonth As String

intListIndex = Combo1.ListIndex

strMonth = arrMonth(intListIndex)
Rst.Open "Select * From " & strMonth, conn

If Rst.RecordCount > 0 Then
n.Text = Rst.Fields("n").Value & ""

Text1(0).Text = Rst.Fields("zy1").Value & ""
Text1(1).Text = Rst.Fields("zy2").Value & ""
Text1(2).Text = Rst.Fields("zy3").Value & ""
Text1(3).Text = Rst.Fields("zy4").Value & ""
Text1(4).Text = Rst.Fields("zy5").Value & ""
Text1(5).Text = Rst.Fields("zy6").Value & ""
Text1(6).Text = Rst.Fields("zy7").Value & ""
Text1(7).Text = Rst.Fields("zy8").Value & ""
Text1(8).Text = Rst.Fields("zy9").Value & ""
Text2(0).Text = Rst.Fields("z(1)").Value & ""
Text2(1).Text = Rst.Fields("z(2)").Value & ""
Text2(2).Text = Rst.Fields("z(3)").Value & ""
Text2(3).Text = Rst.Fields("z(4)").Value & ""
Text2(4).Text = Rst.Fields("z(5)").Value & ""
Text2(5).Text = Rst.Fields("z(6)").Value & ""
Text2(6).Text = Rst.Fields("z(7)").Value & ""
Text2(7).Text = Rst.Fields("z(8)").Value & ""
Text2(8).Text = Rst.Fields("z(9)").Value & ""
Text3(0).Text = Rst.Fields("m1").Value & ""
Text3(1).Text = Rst.Fields("m2").Value & ""
Text3(2).Text = Rst.Fields("m3").Value & ""
Text3(3).Text = Rst.Fields("m4").Value & ""
Text3(4).Text = Rst.Fields("m5").Value & ""
Text3(5).Text = Rst.Fields("m6").Value & ""
Text3(6).Text = Rst.Fields("m7").Value & ""
Text3(7).Text = Rst.Fields("m8").Value & ""
Text3(8).Text = Rst.Fields("m9").Value & ""
Text4(0).Text = Rst.Fields("j(1)").Value & ""
Text4(1).Text = Rst.Fields("j(2)").Value & ""
Text4(2).Text = Rst.Fields("j(3)").Value & ""
Text4(3).Text = Rst.Fields("j(4)").Value & ""
Text4(4).Text = Rst.Fields("j(5)").Value & ""
Text4(5).Text = Rst.Fields("j(6)").Value & ""
Text4(6).Text = Rst.Fields("j(7)").Value & ""
Text4(7).Text = Rst.Fields("j(8)").Value & ""
Text4(8).Text = Rst.Fields("j(9)").Value & ""
Text4(9).Text = Rst.Fields("j10").Value & ""
Text5(0).Text = Rst.Fields("d(1)").Value & ""
Text5(1).Text = Rst.Fields("d(2)").Value & ""
Text5(2).Text = Rst.Fields("d(3)").Value & ""
Text5(3).Text = Rst.Fields("d(4)").Value & ""
Text5(4).Text = Rst.Fields("d(5)").Value & ""
Text5(5).Text = Rst.Fields("d(6)").Value & ""
Text5(6).Text = Rst.Fields("d(7)").Value & ""
Text5(7).Text = Rst.Fields("d(8)").Value & ""
Text5(8).Text = Rst.Fields("d(9)").Value & ""
Text5(9).Text = Rst.Fields("d10").Value & ""
Label14.Caption = Rst.AbsolutePosition
Label16.Caption = Rst.AbsolutePosition

Label11.Caption = Rst.RecordCount
Else

n.Text = ""

Text1(0).Text = ""
Text1(1).Text = ""
Text1(2).Text = ""
Text1(3).Text = ""
Text1(4).Text = ""
Text1(5).Text = ""
Text1(6).Text = ""
Text1(7).Text = ""
Text1(8).Text = ""
Text2(0).Text = ""
Text2(1).Text = ""
Text2(2).Text = ""
Text2(3).Text = ""
Text2(4).Text = ""
Text2(5).Text = ""
Text2(6).Text = ""
Text2(7).Text = ""
Text2(8).Text = ""
Text3(0).Text = ""
Text3(1).Text = ""
Text3(2).Text = ""
Text3(3).Text = ""
Text3(4).Text = ""
Text3(5).Text = ""
Text3(6).Text = ""
Text3(7).Text = ""
Text3(8).Text = ""
Text4(0).Text = ""
Text4(1).Text = ""
Text4(2).Text = ""
Text4(3).Text = ""
Text4(4).Text = ""
Text4(5).Text = ""
Text4(6).Text = ""
Text4(7).Text = ""
Text4(8).Text = ""
Text4(9).Text = ""
Text5(0).Text = ""
Text5(1).Text = ""
Text5(2).Text = ""
Text5(3).Text = ""
Text5(4).Text = ""
Text5(5).Text = ""
Text5(6).Text = ""
Text5(7).Text = ""
Text5(8).Text = ""
Text5(9).Text = ""

Label11.Caption = ""
Label14.Caption = ""
Label16.Caption = ""
End If
Text4(9).ForeColor = RGB(0, 0, 150)
Text5(9).ForeColor = RGB(0, 0, 150)

End Sub

Private Sub Form_Load()
Dim ConString As String
Dim i As Integer
For i = 0 To UBound(arrMonth) - 1
arrMonth(i) = "f" & (i + 1) & "表"
Combo1.AddItem arrMonth(i)
Next

ConString = "Provider=Microsoft.Jet.OleDb.4.0;Persist Security Info = False;" _
& "Data Source =" & App.Path & "\db1.mdb;Jet OleDb:"


Set conn = CreateObject("ADODB.Connection")
With conn
.ConnectionString = ConString
.Open
End With
End Sub

还是没有反应!

2007-09-08 17:25
multiple1902
Rank: 8Rank: 8
等 级:贵宾
威 望:42
帖 子:4881
专家分:671
注 册:2007-2-9
收藏
得分:0 
你就不会自己用脑子思考的么

不会自己把strMonth输出来看看的么

arrMonth(i) = "f" & (i + 1) & "表"
2007-09-08 17:33
purana
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:广东-广州
等 级:版主
威 望:66
帖 子:6039
专家分:0
注 册:2005-6-17
收藏
得分:0 
哇塞.
老实说.
很无聊的代码.

我的msn: myfend@
2007-09-08 17:36
multiple1902
Rank: 8Rank: 8
等 级:贵宾
威 望:42
帖 子:4881
专家分:671
注 册:2007-2-9
收藏
得分:0 
这代码 很强大呀
2007-09-08 17:37
lijun337
Rank: 1
等 级:新手上路
帖 子:379
专家分:5
注 册:2006-4-12
收藏
得分:0 

我建了个子程序 :CC :代码如下:

Private Sub cc()
If Rst.RecordCount > 0 Then
n.Text = Rst.Fields("n").Value & ""

Text1(0).Text = Rst.Fields("zy1").Value & ""
。。。
。。。
。。。
End Sub

初步解决了代码臃肿问题!

另外,列表框问题也得到了解决!

Private Sub Combo1_Click()
If Combo1.Text = "一月" Then

Rst.Open "Select * From pzfx1", conn, adOpenKeyset, adLockPessimistic, adCmdText
Call cc
End If

If Combo1.Text = "二月" Then
Rst.Open "Select * From pzfx2", conn, adOpenKeyset, adLockPessimistic, adCmdText
Call cc
End If

If Combo1.Text = "三月" Then
Rst.Open "Select * From pzfx3", conn, adOpenKeyset, adLockPessimistic, adCmdText
Call cc
End If

。。。
。。。

End Sub

2007-09-11 20:31
快速回复:如何把COMBO1控件里的LIST一月、二月、三月、四月与DB1里的F1表、F2表 ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.022538 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved