rs.Open "select * from xinxi where shijian='" & Format$(ListView2.SelectedItem.SubItems(3), "yyyy-mm-dd hh:mm:ss") & "'", cn, 1, 1
  显示数据类型不匹配, 数据库用的是access 日期/时间格式的数据
ListView2.SelectedItem.SubItems(3)的数据是从数据库里面读进去的。 改怎么给他格式化啊?
这是数据库的时间格式:2008-12-25 13:28:33

解决方案 »

  1.   

    rs.Open "select * from xinxi where shijian='" & Format(ListView2.SelectedItem.SubItems(3), "yyyy-MM-dd hh:mm:ss") & "'", cn, 1, 1试一下
    ?什么数据库
    ?shijian什么数据类型
      

  2.   

     数据库用的是Access 日期/时间格式的数据 
     
    我用DateTime.Now 写进去的   shijian是数据库的字段·
    上面的还是显示数据类型不匹配
    看你每个帖子都跑,跑的也挺累的,我都不好意思了,再加点分吧
      

  3.   

    试试:
    rs.Open "select * from xinxi where shijian='" & Format$(cdate(ListView2.SelectedItem.SubItems(3)), "yyyy-mm-dd hh:mm:ss") & "'", cn, 1, 1
      

  4.   

    Format(ListView2.SelectedItem.SubItems(3), 'yyyy-mm-dd hh:mm:ss')
    用单引号,否则会被认为是字符串
    如果还不行的话,试试看先把fotmat两头的单引号去掉
    rs.Open "select * from xinxi where shijian=" & Format(ListView2.SelectedItem.SubItems(3), 'yyyy-mm-dd hh:mm:ss'), cn, 1, 1
      

  5.   

    搞错了,改成
    rs.Open "select * from xinxi where shijian=" & Format(ListView2.SelectedItem.SubItems(3), "yyyy-mm-dd hh:mm:ss"), cn, 1, 1
    试试看
      

  6.   

    rs.Open "select * from xinxi where shijian=#" & Format(ListView2.SelectedItem.SubItems(3), "yyyy-MM-dd hh:mm:ss") & "#", cn, 1, 1
      

  7.   

    rs.Open "select * from xinxi where shijian=#" & Format(ListView2.SelectedItem.SubItems(3), "yyyy-MM-dd hh:mm:ss") & "#", cn, 1, 1数据库用的是Access 日期/时间格式的数据
    在数据前后要加 # #
      

  8.   

    你這是VB.NET吧,在VB6中是可以的,改為如下:
    1、把mDT = convert.datetime(ListView2.SelectedItem.SubItems(3))轉為datetime類型
    2、再用rs.Open "select * from xinxi where shijian='" & Format$(mDT, "yyyy-mm-dd hh:mm:ss") & "'", cn, 1, 1