Private Sub Cmd_Fing_Click()
Dim str As String
  str = InputBox$("输入你要查询的货品编号:", "系统提示")
  If str = "" Then Exit Sub
  Adodc2.RecordSource = "select * from tb_IN where 货品编号='" + str + "'"
  Adodc2.Refresh
  If Adodc2.Recordset.RecordCount > 0 Then
     Text1(1).Text = Adodc2.Recordset.Fields(1)
     Text1(2).Text = Adodc2.Recordset.Fields(2)
     Text1(3).Text = Adodc2.Recordset.Fields(7)
     Text1(4).Text = Adodc2.Recordset.Fields(8)
     Text1(5).Text = Adodc2.Recordset.Fields(14)
      Else
     MsgBox "没有你需要的信息!", , "系统提示"
     End If
End Sub
用查询就出现至少一个参数那个能帮下非常感谢!

解决方案 »

  1.   

    1,检查ADODC2控件是否与数据库绑定
    2,语句中的表名与字段名是否存在
      

  2.   

    Adodc2.RecordSource   =   "select   *   from   tb_IN   where   货品编号= ' "   +   str   +   " ' " 
    改成
    Adodc2.RecordSource   =   "select   *   from   tb_IN   where   货品编号= ' "   &   str   &   " ' " 
      

  3.   


    Adodc2.RecordSource = "select * from tb_IN where 货品编号 = '" & replace(str,"'","''") & "'" 
    Adodc2.Refresh If Adodc2.Recordset.RecordCount > 0 Then
        Text1(1).Text = Adodc2.Recordset.Fields(1)
        Text1(2).Text = Adodc2.Recordset.Fields(2)
        Text1(3).Text = Adodc2.Recordset.Fields(7)
        Text1(4).Text = Adodc2.Recordset.Fields(8)
        Text1(5).Text = Adodc2.Recordset.Fields(14)
    Else
        MsgBox "没有你需要的信息! ", , "系统提示 "
    End If
      

  4.   

    Dim   str   As   String 
    大哥,str是VB保留字,不知道吗?换一个,如str1
      

  5.   

    阿勇: str是么?我一直都这么用的没问题啊Adodc2.RecordSource = "select * from tb_IN where 货品编号 = '" & replace(str,"'","''") & "'" 
    Adodc2.Refresh If Adodc2.Recordset.RecordCount > 0 Then
        Text1(1).Text = Adodc2.Recordset.Fields(1)
        Text1(2).Text = Adodc2.Recordset.Fields(2)
        Text1(3).Text = Adodc2.Recordset.Fields(7)
        Text1(4).Text = Adodc2.Recordset.Fields(8)
        Text1(5).Text = Adodc2.Recordset.Fields(14)
    Else
        MsgBox "没有你需要的信息! ", , "系统提示 "
    End If