vb编程搜索access数据为什么显示空白,程序调试没有发生错误
程序内容如下:
Private Sub Command1_Click()
Dim strSql As String
If Text1.Text <> "" Then
Adodc1.Recordset.Close
If Val(Text1.Text) > 0 Then
strSql = "select * from table1 where num=" & Trim(Text1.Text)
Else
strSql = "select * from table1 where name='" & Trim(Text1.Text) & "'"
End If
Adodc1.CommandType = adCmdText
Adodc1.Recordset.Open strSql
Set DataGrid1.DataSource = Adodc1
Else
Set DataGrid1.DataSource = Nothing
End If
End Sub
问题出在哪里?为什么搜索后插件里显示的是空白的

解决方案 »

  1.   

    这是体育老师教的编程?
    不要直接操作 Adodc1.Recordset,会影响正常的功能!!!
      

  2.   

    请给Adodc1.ConnectionString赋值字符串连接,并用以下代码式样:
    Private Sub Command1_Click()
        Dim strsql As String
        Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Program Files\Microsoft Visual Studio\vb98\nwind.mdb;Persist Security Info=False"
        If Text1.Text <> "" Then
            If Val(Text1.Text) > 0 Then
                strsql = "select * from Customers where Customer ID=" & Trim(Text1.Text)
            Else
                strsql = "select * from Customers where CustomerID='" & Trim(Text1.Text) & "'"
            End If
            Adodc1.RecordSource = strsql
            Adodc1.Refresh
            Set DataGrid1.DataSource = Adodc1
        Else
            Set DataGrid1.DataSource = Nothing
        End If
    End Sub将代码修改为你的数据库名、路径、表名。
      

  3.   

    另外吐槽下,like语句在ide和编译后执行的效果不一致。