你好,请问,我想用1个按钮通过select语句查询odbc 中dsn="WDR" 的数据库 中的表'DE'的列名为'标准时间'中 时间='   '(用vb中的文本框输入的时间) 。使用form1\adodc1\ datagrid1\ text1\command1 当按下 command1 时  datagrid1 就会列出标准时间这列的中时间为 text1 中的时间的所有 的记录行。指针指向 第1条 符合条件的记录。当无记录时 会msgbox"找不到!" 。请 大哥帮忙,很急 谢谢拨冗答复。
我的信箱是[email protected]

解决方案 »

  1.   

    Option Explicit
    '“工程”->“引用”,选中“Microsoft ActiveX Data Objects 2.* Library”
    Dim GCon As New ADODB.ConnectionPrivate Sub Command1_Click()
        Dim rsTest As New ADODB.Recordset
        Dim strSQL As String
        
        If Not IsDate(Text1.Text) Then
            MsgBox "请输入正确格式的日期!", vbInformation, "提示"
            Exit Sub
        End If
        
        strSQL = "select * from DE where 标准时间=#" & Format(Text1.Text, "yyyy-MM-dd hh:mm:ss") & "#"
        rsTest.Open strSQL, GCon, adOpenStatic, adLockOptimistic
        If rsTest.RecordCount < 0 Then
            MsgBox "没有找到匹配记录!", vbInformation, "提示"
        Else
            Set DataGrid1.DataSource = rsTest
        End If
    End SubPrivate Sub Form_Load()
        GCon.CursorLocation = adUseClient
        GCon.Open "DSN=WDR;UID=;PWD="
    End Sub
      

  2.   

    Dim rsTest As New ADODB.Recordset
        Dim strSQL As String
      
        strSQL = "select * from DE where 标准时间=Text1.text"   '''这里有误 怎么改呢,变量的问题 格式不对。。??
        rsTest.Open strSQL, GCon, adOpenStatic, adLockOptimistic
        If rsTest.RecordCount < 0 Then
            MsgBox "没有找到匹配记录!", vbInformation, "提示"
        Else
            Set DataGrid1.DataSource = rsTest
        End If
      

  3.   

    楼主看仔细了:
    strSQL = "select * from DE where 标准时间=Text1.text"
    应为:
    strSQL = "select * from DE where 标准时间='" & Text1.text & "'"  '(SQL Server中)

    strSQL = "select * from DE where 标准时间=#" & Text1.text & "#"  '(Access中)
      

  4.   

    我在Text 中输入 8.5  点 command 后 datagrid 没反映
    strSQL = "select * from DE where 标准时间='8.5'"  则datagrid得出 所有的 符合的记录