目的:
1、通过SQL语句查询将一张表(临时表)中符合条件的记录在DataGrid中显示出来...2、datagrid在窗体刚加载的时候要显示出默认的数据库("\my_mdb.mdb")“临时表”的数据3、在窗体刚加载的时候将Access中某张表(指定表)的数据复制到同一个数据库中另一张表“临时
   表”里面,临时表使用完以后要清空(窗体卸载时)。。貌似现在我解决不了的就这个问题,我SQL语句根本是不会用,请各路高手帮我解决哈。。

解决方案 »

  1.   

    SQL = "select * from 临时表 where " & cx_fx & " = " & Text1.Text & ""这是我写的,只会这一点了....高手们,拜托啦..
      

  2.   

    2.    Dim adoConn As New ADODB.Connection
        Dim rst As New ADODB.Recordset
        Dim s As String    If adoConn.State = adStateClosed Then
            adoConn.Open "Driver={Microsoft Access Driver (*.mdb)};Dbq=" & App.Path & "\my_mdb.mdb;DefaultDir=" & App.Path & "\"
        End If
        
        rst.CursorLocation = adUseClient
        rst.Open s, adoConn, adOpenDynamic, adLockOptimistic
        Set DataGrid1.DataSource = rst
        rst.Close
    3.s="insert into 临时表 from 指定表"'复制
    adoConn.Execute ss="delete * from 临时表"'删除
    adoConn.Execute s
      

  3.   

    目的:
    1、通过SQL语句查询将一张表(临时表)中符合条件的记录在DataGrid中显示出来...
    SQL="Select * From 臨時表Name Where ColName='條件A'"
    2、datagrid在窗体刚加载的时候要显示出默认的数据库("\my_mdb.mdb")“临时表”的数据
    在Form_Load中 Con.Connection="...,DataSource=App.Path &"\my_mdb.mdb";..."
     SQL="Select * From 臨時表Name "
    3、在窗体刚加载的时候将Access中某张表(指定表)的数据复制到同一个数据库中另一张表“临时
       表”里面,临时表使用完以后要清空(窗体卸载时)。。
    還是在Form Load裏面
    Insert Into 臨時表Name Select * From 臨時表NameA Where 條件 最好加條件判斷防止插入不需要的數據的數據(可能需要)
    再Form Unload裏面
    Delete From 臨時表Name
      

  4.   

    有点迷糊....加进去说缺少语句结束
    Private Sub Command1_Click()
     Dim cn As adodb.Connection, rs As adodb.RecordsetSet cn = New adodb.Connection
    cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\access\vipfwxt.mdb"Set rs = New Recordset
    rs.Open "select * from 客户基本资料详情表 where '" & cx_fx & "' = '" & Text1.Text & "'", cn, 1, 1, -1If Not rs.EOF Then
    text2 = ""
    End If'Set DataGrid1.DataSource = rsrs.Close
    Set rs = Nothing
    cn.Close
    Set cn = Nothing
    End Sub这段代码为什么查不出来呢??
      

  5.   

    rs.Open "select * from 客户基本资料详情表 where '" & cx_fx & "' = '" & Text1.Text & "'", cn, 1, 1, -1
    '" & cx_fx & "'者個是變量嗎?
    如果時列名不用這樣寫
    直接寫成
    rs.Open "select * from 客户基本资料详情表 where  cx_fx  = '" & Text1.Text & "'", cn, 1, 1
    如果是變量
    最好用
    Set Rs=Con.Execute("select * from 客户基本资料详情表 where '" & cx_fx & "' = '" & Text1.Text & "'")
    看看
      

  6.   

    Private Sub Command1_Click()
     Dim cn As adodb.Connection, rs As adodb.RecordsetSet cn = New adodb.Connection
    cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\access\vipfwxt.mdb"Set rs = New Recordset
    Set rs = cn.Execute("select * from 客户基本资料详情表 where '" & cx_fx & "' = '" & Text1.Text & "'")
    If Not rs.EOF Then
    MsgBox "查无此人"
    End If
    MsgBox "查询成功"
    Set DataGrid1.DataSource = rs  --------运行到此处会提示"行集合不能为标签"rs.Close
    Set rs = Nothing
    cn.Close
    Set cn = Nothing
    End Sub测试结果不管我输入什么字段查询.最后都会提示查询成功..昏迷.....快99我
      

  7.   

    錯了
    Set rs = cn.Execute("select * from 客户基本资料详情表 where " & cx_fx & " = '" & Text1.Text & "'")
    這樣再看看
      

  8.   

    肯定會提示查詢成功的啊,因爲你的MsgBox "查询成功"每次都被執行到
    如果你想做錯誤處理的話應該是
    Private Sub Command1_Click()
    On Error Goto Click_Err
    .
    .
    .
    Exit Sub
    Click_Err:
             MsgBox"錯誤原因:'"& Err.D &"'"
      

  9.   

    Set rs = cn.Execute("select * from 客户基本资料详情表 where '" & cx_fx & "' = '" & Text1.Text & "'")这儿错了,'" & cx_fx & "'不需要加单引号,改成
    Set rs = cn.Execute("select * from 客户基本资料详情表 where " & cx_fx & " = '" & Text1.Text & "'")另外,
    If Not rs.EOF Then
    MsgBox "查无此人"
    End If
    MsgBox "查询成功"此处楼主的意思应该是这样的吧:
    If Not rs.EOF Then
       MsgBox "查无此人"
    ELSE
       MsgBox "查询成功"
    End If
      

  10.   

    你看下這個http://blog.csdn.net/cly2004/archive/2005/03/29/333304.aspx