注册 登录
编程论坛 VB6论坛

查询语句出错,不知道错在哪了!帮我看看,谢谢

wxflw 发布于 2013-04-23 20:49, 505 次点击
为什么我combo6选择了“电气类”就出错,提示搜索引擎找不到输入表或查询“电器类”?我选择模具类或设备类就不出错!郁闷了!表格内容一样的,只是表名不同
请帮我看看!我头晕了,在线等!

Option Explicit
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim sql As String


Private Sub Form_Load()
Set cn = New ADODB.Connection
Set rs = New ADODB.Recordset
Combo1.Clear
Combo2.Clear
Combo3.Clear
Combo4.Clear
Combo5.Clear
Combo6.Clear
Combo6.AddItem "电器类"
Combo6.AddItem "模具类"
Combo6.AddItem "设备类"

Combo6.Text = Combo6.List(0)
If Combo6.Text = "电器类" Then
   Combo5.Visible = False
   Label5.Visible = False
   Else
   Combo5.Visible = True
   Label5.Visible = True
End If
End Sub

Private Sub Command1_Click() '查询
 If cn.State = adStateOpen Then cn.Close
    If rs.State = adStateOpen Then rs.Close
    cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\beijian.mdb;Persist Security Info=False"
    sql = "select * from " & Combo6.Text & ""
    rs.Open sql, cn, 3, 3
   If rs.EOF And rs.BOF Then
      MsgBox "没有记录", 32, "系统"
      If cn.State = adStateOpen Then cn.Close
      If rs.State = adStateOpen Then rs.Close
      Exit Sub
    Else
    Set MSHFlexGrid1.DataSource = rs
    Label6.Caption = "总共查询到:" & rs.RecordCount & "条记录!"
   End If
End Sub
2 回复
#2
wxflw2013-04-23 20:50
一个数据库里有3张表格分别是,模具类,电器类,设备类
#3
wxflw2013-04-23 21:11
不好意思,是我的数据库出问题了,麻烦大家了
1