| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1355 人关注过本帖
标题:[求助]为什么我用了SELECT CASE语句后就不能查询了?
只看楼主 加入收藏
Nekomimi
Rank: 2
等 级:论坛游民
帖 子:80
专家分:15
注 册:2006-11-21
结帖率:100%
收藏
 问题点数:0 回复次数:8 
[求助]为什么我用了SELECT CASE语句后就不能查询了?
我设置了很多cmdFind按钮数组,还有很多Combox的数组,其中有两个按钮是根据Combo1()不同,而查询出不同的结果
Private Sub cmdFind_Click(Index As Integer)
Adodc1.ConnectionString = connstring
Select Case Index
Case 0
Select Case FindIndex
Case 0
strsql = "SELECT 。。。。省略"
Case 1
strsql = "SELECT 。。。。省略"
。。。。。。。省略
End Select
Adodc1.RecordSource = strsql
Adodc1.Refresh
If Adodc1.Recordset.RecordCount > 0 Then
For i = 0 To 10
Text1(i).Text = Adodc1.Recordset.Fields(i)
Next i
Adodc2.RecordSource = strsql2
Adodc2.Refresh
Set DataGrid1.DataSource = Adodc2
Else
MsgBox "。。。略", vbCritical
Exit Sub
End If
(这里正常,没问题)
CASE 1
。。。。
Case 2
。。。。。
。。。。。
Case 6 (问题来了。。。- -)
Select Case FindIndex
Case 13
strsql = "SELECT 。。。。省略"
Case 14
strsql = "SELECT 。。。。省略"
。。。。。。。省略
End Select
Adodc1.RecordSource = strsql
Adodc1.Refresh
If Adodc1.Recordset.RecordCount > 0 Then
For i = 11To 21
Text1(i).Text = Adodc1.Recordset.Fields(i-11)
Next i
Adodc2.RecordSource = strsql2
Adodc2.Refresh
Set DataGrid1.DataSource = Adodc2
Else
MsgBox "。。。略", vbCritical
Exit Sub
End If

点击cmdFind(6)之后,弹出:
[ADODC]:没有指定记录源。[ADO]:没有为命令对象设置命令。
这个到底是什么地方出错了啊???
搜索更多相关主题的帖子: SELECT CASE 语句 Case strsql 
2006-11-28 23:12
Nekomimi
Rank: 2
等 级:论坛游民
帖 子:80
专家分:15
注 册:2006-11-21
收藏
得分:0 
再补充一点。。。这是最怪异的一点:
先从下拉菜单Combo1(14)中选择,然后点击cmdFind(6),出来结果;然后从下拉菜单Combo1(13)中选择,然后点击cmdFind(6),也能出来结果,正常。
但是如果一开始就从下拉菜单Combo1(13)中选择,然后点击cmdFind(6)的话,就会弹出我说的那个对话框。。。。
2006-11-28 23:52
purana
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:广东-广州
等 级:版主
威 望:66
帖 子:6039
专家分:0
注 册:2005-6-17
收藏
得分:0 
感觉很乱...还是发完整一些吧..

我的msn: myfend@
2006-11-29 13:29
Nekomimi
Rank: 2
等 级:论坛游民
帖 子:80
专家分:15
注 册:2006-11-21
收藏
得分:0 

小弟能力有限,程序很冗长。。。。我再简化一下,多发点吧。。。。:
Private Sub FindFormInit()
DataGrid1.AllowUpdate = False
DataGrid2.AllowUpdate = False
cmdFind(2).Enabled = False
cmdFind(3).Enabled = False
cmdFind(9).Enabled = False
cmdFind(10).Enabled = False
Option1(0).Value = True
Option1(12).Value = True
FindIndex = 0
(下面设置了24个下拉菜单。。不用一一列出来了吧。。)
Adodc1.ConnectionString = connstring
strsql = "select a,b,c from s where a in ('140W','140')"
Adodc1.RecordSource = strsql
Adodc1.Refresh
If Adodc1.Recordset.RecordCount <> 0 Then
Adodc1.Recordset.MoveFirst
Do While Not Adodc1.Recordset.EOF
Combo1(0).AddItem Adodc1.Recordset.Fields(0)
Combo1(12).AddItem Adodc1.Recordset.Fields(0)
Adodc1.Recordset.MoveNext
Loop
Else
' MsgBox "", vbCritical
End If

strsql = "select a,b,c from s where a in ('141W','141')"
Adodc1.RecordSource = strsql
Adodc1.Refresh
If Adodc1.Recordset.RecordCount <> 0 Then
Adodc1.Recordset.MoveFirst
Do While Not Adodc1.Recordset.EOF
Combo1(1).AddItem Adodc1.Recordset.Fields(0)
Combo1(13).AddItem Adodc1.Recordset.Fields(0)
Adodc1.Recordset.MoveNext
Loop
Else
' MsgBox "", vbCritical
End If

。。。。。。。。。。。。。。略

strsql = "select a,b,c from s where a = '6D1'"
Adodc1.RecordSource = strsql
Adodc1.Refresh
If Adodc1.Recordset.RecordCount <> 0 Then
Adodc1.Recordset.MoveFirst
Do While Not Adodc1.Recordset.EOF
Combo1(11).AddItem Adodc1.Recordset.Fields(0)
Combo1(23).AddItem Adodc1.Recordset.Fields(0)
Adodc1.Recordset.MoveNext
Loop
Else
' MsgBox "", vbCritical
Exit Sub
End If
End Sub
Private Sub Option1_Click(Index As Integer)
Select Case Index
Case 0
Combo1(0).Enabled = True
Combo1(1).Enabled = False
Combo1(2).Enabled = False
Combo1(3).Enabled = False
Combo1(4).Enabled = False
Combo1(5).Enabled = False
Combo1(6).Enabled = False
Combo1(7).Enabled = False
Combo1(8).Enabled = False
Combo1(9).Enabled = False
Combo1(10).Enabled = False
Combo1(11).Enabled = False
Combo1(1).Text = ""
Combo1(2).Text = ""
Combo1(3).Text = ""
Combo1(4).Text = ""
Combo1(5).Text = ""
Combo1(6).Text = ""
Combo1(7).Text = ""
Combo1(8).Text = ""
Combo1(9).Text = ""
Combo1(10).Text = ""
Combo1(11).Text = ""
Case 1
Combo1(0).Enabled = False
Combo1(1).Enabled = True
Combo1(2).Enabled = False
Combo1(3).Enabled = False
Combo1(4).Enabled = False
Combo1(5).Enabled = False
Combo1(6).Enabled = False
Combo1(7).Enabled = False
Combo1(8).Enabled = False
Combo1(9).Enabled = False
Combo1(10).Enabled = False
Combo1(11).Enabled = False
Combo1(0).Text = ""
Combo1(2).Text = ""
Combo1(3).Text = ""
Combo1(4).Text = ""
Combo1(5).Text = ""
Combo1(6).Text = ""
Combo1(7).Text = ""
Combo1(8).Text = ""
Combo1(9).Text = ""
Combo1(10).Text = ""
Combo1(11).Text = ""
(Case 2~Case 10的内容。。估计看了其他的就能够知道了吧。。我用的是最笨的方法,全部列出来)
Case 11
Combo1(0).Enabled = False
Combo1(1).Enabled = False
Combo1(2).Enabled = False
Combo1(3).Enabled = False
Combo1(4).Enabled = False
Combo1(5).Enabled = False
Combo1(6).Enabled = False
Combo1(7).Enabled = False
Combo1(8).Enabled = False
Combo1(9).Enabled = False
Combo1(10).Enabled = False
Combo1(11).Enabled = True
Combo1(1).Text = ""
Combo1(2).Text = ""
Combo1(3).Text = ""
Combo1(4).Text = ""
Combo1(5).Text = ""
Combo1(6).Text = ""
Combo1(7).Text = ""
Combo1(8).Text = ""
Combo1(9).Text = ""
Combo1(10).Text = ""
Combo1(0).Text = ""
Case 12
Combo1(12).Enabled = True
Combo1(13).Enabled = False
Combo1(14).Enabled = False
Combo1(15).Enabled = False
Combo1(16).Enabled = False
Combo1(17).Enabled = False
Combo1(18).Enabled = False
Combo1(19).Enabled = False
Combo1(20).Enabled = False
Combo1(21).Enabled = False
Combo1(22).Enabled = False
Combo1(23).Enabled = False
Combo1(13).Text = ""
Combo1(14).Text = ""
Combo1(15).Text = ""
Combo1(16).Text = ""
Combo1(17).Text = ""
Combo1(18).Text = ""
Combo1(19).Text = ""
Combo1(20).Text = ""
Combo1(21).Text = ""
Combo1(22).Text = ""
Combo1(23).Text = ""
(Case 13~Case 22的内容。。也同上方法)
Case 23
Combo1(12).Enabled = False
Combo1(13).Enabled = False
Combo1(14).Enabled = False
Combo1(15).Enabled = False
Combo1(16).Enabled = False
Combo1(17).Enabled = False
Combo1(18).Enabled = False
Combo1(19).Enabled = False
Combo1(20).Enabled = False
Combo1(21).Enabled = False
Combo1(22).Enabled = False
Combo1(23).Enabled = True
Combo1(12).Text = ""
Combo1(13).Text = ""
Combo1(14).Text = ""
Combo1(15).Text = ""
Combo1(16).Text = ""
Combo1(17).Text = ""
Combo1(18).Text = ""
Combo1(19).Text = ""
Combo1(20).Text = ""
Combo1(21).Text = ""
Combo1(22).Text = ""
End Select
FindIndex = Index
End Sub

Private Sub cmdFind_Click(Index As Integer)
Adodc1.ConnectionString = connstring
Adodc2.ConnectionString = connstring
Adodc3.ConnectionString = connstring
Adodc4.ConnectionString = connstring
Adodc5.ConnectionString = connstring
Adodc6.ConnectionString = connstring

Select Case Index
Case 0 Select Case FindIndex
Case 0
strsql = "SELECT a,b,c, FROM s Where b = '" + Trim(Combo1(0).Text) + "' AND a in('140W','140')"
strsql2 = "SELECT d,e,f FROM x Where b = '" + Trim(Combo1(0).Text) + "' AND a in('140W','140')"
Case 1
strsql = "SELECT a,b,c, FROM s Where b = '" + Trim(Combo1(1).Text) + "' AND a in('141W','141')"
strsql2 = "SELECT a,b,c, FROM x Where b = '" + Trim(Combo1(1).Text) + "' AND a in('141W','141')"
Case 2
.....
Case 3

.....
Case 4
......
Case 5
......
Case 6
......
Case 7
......
Case 8
......
Case 9
......
Case 10
......
Case 11
strsql = "SELECT a,b,c, FROM s Where b = '" + Trim(Combo1(11).Text) + "' AND a ='6D1'"
strsql2 = "SELECT a,b,c, FROM x Where b = '" + Trim(Combo1(11).Text) + "' AND a ='6D1'"
End Select

Adodc1.RecordSource = strsql
Adodc1.Refresh
If Adodc1.Recordset.RecordCount > 0 Then
For i = 0 To 10
Text1(i).Text = Adodc1.Recordset.Fields(i)
Next i
Adodc2.RecordSource = strsql2
Adodc2.Refresh
Set DataGrid1.DataSource = Adodc2
Else
MsgBox " ", vbCritical
Exit Sub
End If

Case 1
Option1(0).Value = False
For i = 0 To 11
Combo1(i).Enabled = False
Combo1(i).Text = ""
Next i
cmdFind(2).Enabled = True
cmdFind(3).Enabled = True
For i = 0 To 10
Text1(i).Text = ""
Next i
DataGrid1.AllowUpdate = True
DataGrid1.AllowAddNew = True
cmdFind(1).Visible = False
cmdFind(5).Visible = True
cmdFind(0).Enabled = False
Frame8.Visible = True
For i = 26 To 32
Label1(i).Visible = True
Next i
For i = 22 To 28
Text1(i).Visible = True
Next i
For i = 29 To 35
Text1(i).Visible = True
Next i
For i = 36 To 42
Text1(i).Visible = True
Next i
For i = 43 To 49
Text1(i).Visible = True
Next i
For i = 50 To 56
Text1(i).Visible = True
Next i
DataGrid1.Visible = False
Case 2
strsql = "SELECT a,b,c FROM s Where a = '" + Trim(Text1(3).Text) + "' AND b='" + Trim(Text1(2).Text) + "'"
strsql2 = "SELECT d,e,f FROM x Where a = '" + Trim(Text1(3).Text) + "' AND b='" + Trim(Text1(2).Text) +"'"
strsql3 = "SELECT 略了吧"
strsql4 = "SELECT 略"
Adodc1.RecordSource = strsql
Adodc1.Refresh

Adodc1.Recordset.AddNew
For i = 0 To 10
Adodc1.Recordset.Fields(i) = Text1(i).Text
Next i
Adodc1.Recordset.Update

Adodc2.RecordSource = strsql2
Adodc2.Refresh
Adodc2.Recordset.AddNew
Adodc2.Recordset.Fields(0) = Text1(2).Text
Adodc2.Recordset.Fields(1) = Text1(3).Text
For i = 22 To 28
Adodc2.Recordset.Fields(i - 20) = Text1(i).Text
Next i
Adodc2.Recordset.Update

Adodc3.RecordSource = strsql3
Adodc3.Refresh
Adodc3.Recordset.AddNew
Adodc3.Recordset.Fields(0) = Trim(Text1(2).Text)
Adodc3.Recordset.Fields(1) = Trim(Text1(3).Text)
For i = 29 To 35
Adodc3.Recordset.Fields(i - 27) = Trim(Text1(i).Text)
Next i
Adodc3.Recordset.Update

Adodc4.RecordSource = strsql4
Adodc4.Refresh
Adodc4.Recordset.AddNew
Adodc4.Recordset.Fields(0) = Trim(Text1(2).Text)
Adodc4.Recordset.Fields(1) = Trim(Text1(3).Text)
For i = 36 To 42
Adodc4.Recordset.Fields(i - 34) = Trim(Text1(i).Text)
Next i
Adodc4.Recordset.Update

Adodc5.RecordSource = strsql3
Adodc5.Refresh
Adodc5.Recordset.AddNew
Adodc5.Recordset.Fields(0) = Trim(Text1(2).Text)
Adodc5.Recordset.Fields(1) = Trim(Text1(3).Text)
For i = 43 To 49
Adodc5.Recordset.Fields(i - 41) = Trim(Text1(i).Text)
Next i
Adodc5.Recordset.Update

Adodc6.RecordSource = strsql4
Adodc6.Refresh
Adodc6.Recordset.AddNew
Adodc6.Recordset.Fields(0) = Trim(Text1(2).Text)
Adodc6.Recordset.Fields(1) = Trim(Text1(3).Text)
For i = 50 To 56
Adodc6.Recordset.Fields(i - 48) = Trim(Text1(i).Text)
Next i
Adodc6.Recordset.Update

MsgBox "", vbInformation + vbOKOnly, ""
For i = 0 To 10
Text1(i).Text = ""
Next i
For i = 22 To 56
Text1(i).Text = ""
Next i

strsql = "select 。。。"
Adodc1.RecordSource = strsql
Adodc1.Refresh
Adodc1.Recordset.AddNew
Adodc1.Recordset.Fields(0) = gUserName
Adodc1.Recordset.Fields(1) = ""
Adodc1.Recordset.Fields(2) = Date
Adodc1.Recordset.Fields(3) = time
Adodc1.Recordset.Update
(记录操作的dd。。)

'刷新下拉菜单
For i = 0 To 24
Combo1(i).Clear
Next
(和上面设置下拉菜单的代码一样。。略)
Case 3
For i = 0 To 10
Text1(i).Text = ""
Next i
For i = 22 To 56
Text1(i).Text = ""
Next i

Case 4
Unload Me
End

Case 5
DataGrid1.AllowUpdate = False
DataGrid1.AllowAddNew = False
cmdFind(1).Visible = True
cmdFind(5).Visible = False
cmdFind(0).Enabled = True
cmdFind(2).Enabled = False
cmdFind(3).Enabled = False
Option1(0).Value = True
Frame8.Visible = False
For i = 26 To 32
Label1(i).Visible = False
Next i
For i = 22 To 28
Text1(i).Visible = False
Next i
For i = 29 To 35
Text1(i).Visible = False
Next i
For i = 36 To 42
Text1(i).Visible = False
Next i
For i = 43 To 49
Text1(i).Visible = False
Next i
For i = 50 To 56
Text1(i).Visible = False
Next i
DataGrid1.Visible = True

Case 6
Select Case FindIndex
Case 12
strsql = "SELECT ...略"
strsql2= "SELECT ...略"
除了Trim(Combo1(0).text)变为Trim(Combo1(12).text)外,其余同Case 0
Case 13
( 变化同上,下面的都略了吧,反正都是下拉菜单变了,而下拉内容不变的情况)
Case 14
Case 15
Case 16
Case 17
Case 18
Case 19
Case 20
Case 21
Case 22
Case 23
End Select

Adodc1.RecordSource = strsql
Adodc1.Refresh
If Adodc1.Recordset.RecordCount > 0 Then
For i = 11 To 21
Text1(i).Text = Adodc1.Recordset.Fields(i - 11)
Next i
Adodc2.RecordSource = strsql2
Adodc2.Refresh
Set DataGrid2.DataSource = Adodc2

Else
MsgBox "", vbCritical
Exit Sub
End If
Case 7

cmdFind(9).Enabled = True
cmdFind(10).Enabled = True
DataGrid2.AllowUpdate = True
DataGrid2.AllowAddNew = True
DataGrid2.AllowDelete = True
cmdFind(7).Visible = False
cmdFind(8).Visible = True

Case 8
cmdFind(9).Enabled = False
cmdFind(10).Enabled = False
DataGrid2.AllowUpdate = False
DataGrid2.AllowAddNew = False
DataGrid2.AllowDelete = False
cmdFind(7).Visible = True
cmdFind(8).Visible = False

Case 9
With Adodc1.Recordset
.Delete
If .EOF Then
.MoveLast
Else
.MoveNext
End If
End With
strsql = "SELECT "
strsql2 = "SELECT "

Adodc1.RecordSource = strsql
Adodc1.Refresh
Adodc1.Recordset.AddNew
For i = 11 To 21
Adodc1.Recordset.Fields(i - 11) = Text1(i).Text
Text1(i).Text = ""
Next i
Adodc1.Recordset.Update

Adodc2.RecordSource = strsql2
Adodc2.Refresh
Adodc2.Recordset.Update
MsgBox "", vbInformation + vbOKOnly, ""
strsql2 = "SELECT "
Adodc2.RecordSource = strsql2
Adodc2.Refresh
Set DataGrid2.DataSource = Adodc2

strsql = "select "
Adodc1.RecordSource = strsql
Adodc1.Refresh
Adodc1.Recordset.AddNew
Adodc1.Recordset.Fields(0) = gUserName
Adodc1.Recordset.Fields(1) = ""
Adodc1.Recordset.Fields(2) = Date
Adodc1.Recordset.Fields(3) = time
Adodc1.Recordset.Update

Case 10
If MsgBox("", vbExclamation + vbOKCancel, "") = vbCancel Then
Exit Sub
End If

With Adodc1.Recordset
If .RecordCount <= 0 Then
MsgBox "", vbInformation + vbOKOnly, ""
Exit Sub
End If
.Delete
If .EOF Then
.MoveLast
Else
.MoveNext
End If
For i = 11 To 21
Text1(i).Text = ""
Next i
End With

With Adodc2.Recordset
If .RecordCount > 0 Then
.Delete
Else
End If
If .EOF Then
.MoveLast
Else
.MoveNext
End If
End With

strsql2 = "SELECT "
Adodc2.RecordSource = strsql2
Adodc2.Refresh
Set DataGrid2.DataSource = Adodc2

strsql = "select "
Adodc1.RecordSource = strsql
Adodc1.Refresh
Adodc1.Recordset.AddNew
Adodc1.Recordset.Fields(0) = gUserName
Adodc1.Recordset.Fields(1) = ""
Adodc1.Recordset.Fields(2) = Date
Adodc1.Recordset.Fields(3) = time
Adodc1.Recordset.Update

Case 11
Unload Me
End

End Select
End Sub

2006-11-29 15:43
学习VB才2天
Rank: 5Rank: 5
等 级:贵宾
威 望:16
帖 子:1653
专家分:0
注 册:2006-5-4
收藏
得分:0 
Combo1(1).Text = ""
Combo1(2).Text = ""
Combo1(3).Text = ""
Combo1(4).Text = ""
Combo1(5).Text = ""
Combo1(6).Text = ""
Combo1(7).Text = ""
Combo1(8).Text = ""
Combo1(9).Text = ""
Combo1(10).Text = ""
Combo1(0).Text = ""
不用这样吧....
for i = 0 to 10
combo(i).text =""
next i

[GLOW=255,DeepPink,3]我的免费网盘[/GLOW]
2006-11-29 19:47
Nekomimi
Rank: 2
等 级:论坛游民
帖 子:80
专家分:15
注 册:2006-11-21
收藏
得分:0 
以下是引用学习VB才2天在2006-11-29 19:47:20的发言:
Combo1(1).Text = ""
Combo1(2).Text = ""
Combo1(3).Text = ""
Combo1(4).Text = ""
Combo1(5).Text = ""
Combo1(6).Text = ""
Combo1(7).Text = ""
Combo1(8).Text = ""
Combo1(9).Text = ""
Combo1(10).Text = ""
Combo1(0).Text = ""
不用这样吧....
for i = 0 to 10
combo(i).text =""
next i

我写这段的时候还没学for next 呢。。。
这个不是我问的重点啊。。。Otz...........

2006-11-29 22:00
学习VB才2天
Rank: 5Rank: 5
等 级:贵宾
威 望:16
帖 子:1653
专家分:0
注 册:2006-5-4
收藏
得分:0 
[ADODC]:没有指定记录源。[ADO]:没有为命令对象设置命令。
这个是语句SQL命令不全的意思...自己找一下....

[GLOW=255,DeepPink,3]我的免费网盘[/GLOW]
2006-11-30 08:28
Nekomimi
Rank: 2
等 级:论坛游民
帖 子:80
专家分:15
注 册:2006-11-21
收藏
得分:0 
以下是引用学习VB才2天在2006-11-30 8:28:03的发言:
[ADODC]:没有指定记录源。[ADO]:没有为命令对象设置命令。
这个是语句SQL命令不全的意思...自己找一下....

Case 0 和Case 6一样的啊,为什么就Case 6有问题?
而且Case 6里面,如果先使用Combo1(13)~Combo1(23)再使用Combo1(12)就没有问题。。
如果SQL语句有问题的话,Case 0就应该错了吧,Case 6也不应该出现我说的那种情况啊。。。

2006-11-30 13:39
学习VB才2天
Rank: 5Rank: 5
等 级:贵宾
威 望:16
帖 子:1653
专家分:0
注 册:2006-5-4
收藏
得分:0 
提供数据不存在或者数据不正确都会出现错误...

[GLOW=255,DeepPink,3]我的免费网盘[/GLOW]
2006-12-01 10:14
快速回复:[求助]为什么我用了SELECT CASE语句后就不能查询了?
数据加载中...
 
   



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

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