SQL语句的问题 ,  多学点SQL语句就可以了

解决方案 »

  1.   

    public rs as new adodb.recordest
    查出记录后,在SQL语句中排序是:order by 字段名
    在程序中排序是rs.sort="字段名"
      

  2.   

    刚开始我是用语句:adodc1.connectionsting="dsn=aaa" 
    adodc1.recordersource="select * from bb "
    datagrid1.datasource=adodc1
    等等做了一系列操作,我现在想在同一程序中把recordersource属性换成表,不是用SQL语句了,我该怎么做?
      

  3.   

    在一个数据库中有好几个表,请问如何改变RECORDSOURCE属性以改变对不同表的操作,另外如何实现记录排序?谢谢!!!
    刚开始我是用语句:adodc1.connectionsting="dsn=aaa" 
    adodc1.recordersource="select * from bb "
    datagrid1.datasource=adodc1
    等等做了一系列操作,我现在想在同一程序中把recordersource属性换成表,不是用SQL语句了,我该怎么做?
      

  4.   

    adodc1.connectionsting="dsn=aaa" 
    adodc1.recordersource="select * from bb "
    datagrid1.datasource=adodc1
    以上是你的原句,
    换成不同的表,只用换sql语句。可以这样写
    adodc1.connectionsting="dsn=aaa" 
    adodc1.recordersource="select * from 表名"
    adodc1.Refresh
    DataGrid1.ClearFields
    DataGrid1.ReBind
     
      

  5.   

    用惯语句编程,不会用控件了,就胡说八道,胡乱回答?
    '''''
    刚开始我是用语句:adodc1.connectionsting="dsn=aaa" 
    adodc1.recordersource="select * from bb "
    datagrid1.datasource=adodc1
    等等做了一系列操作,我现在想在同一程序中把recordersource属性换成表,不是用SQL语句了,我该怎么做?
    '''''
    adodc控件的commandtype属性.鉴别是SQL语句还是表名,把acodc1.commandtype
    改一下就行了
      

  6.   

    Private Sub Command1_Click()Dim Str As String
    Str = "select * from sport where zb='" & Option1(Indx).Caption & "'"
    Adodc1.ConnectionString = "dsn=sport1"
    Adodc1.RecordSource = Str
    Set DataGrid1.DataSource = Adodc1
    While Not Adodc1.Recordset.EOF
    If Adodc1.Recordset.Fields("dw").Value = "体育系" Then
    stucj(0) = stucj(0) + Adodc1.Recordset.Fields("df").Value
    End If
    If Adodc1.Recordset.Fields("dw").Value = "化学系" Then
    stucj(1) = stucj(1) + Adodc1.Recordset.Fields("df").Value
    End If
    If Adodc1.Recordset.Fields("dw").Value = "物理系" Then
    stucj(2) = stucj(2) + Adodc1.Recordset.Fields("df").Value
    End If
    If Adodc1.Recordset.Fields("dw").Value = "中文系" Then
    stucj(3) = stucj(3) + Adodc1.Recordset.Fields("df").Value
    End If
    If Adodc1.Recordset.Fields("dw").Value = "社科系" Then
    stucj(4) = stucj(4) + Adodc1.Recordset.Fields("df").Value
    End If
    If Adodc1.Recordset.Fields("dw").Value = "数学系" Then
    stucj(5) = stucj(5) + Adodc1.Recordset.Fields("df").Value
    End If
    If Adodc1.Recordset.Fields("dw").Value = "外语系" Then
    stucj(6) = stucj(6) + Adodc1.Recordset.Fields("df").Value
    End If
    If Adodc1.Recordset.Fields("dw").Value = "计算机系" Then
    stucj(7) = stucj(7) + Adodc1.Recordset.Fields("df").Value
    End If
    If Adodc1.Recordset.Fields("dw").Value = "工商法律系" Then
    stucj(8) = stucj(8) + Adodc1.Recordset.Fields("df").Value
    End If
    If Adodc1.Recordset.Fields("dw").Value = "初等教育系" Then
    stucj(9) = stucj(9) + Adodc1.Recordset.Fields("df").Value
    End If
    If Adodc1.Recordset.Fields("dw").Value = "艺术与学前教育系" Then
    stucj(10) = stucj(10) + Adodc1.Recordset.Fields("df").Value
    End If
    If Adodc1.Recordset.Fields("dw").Value = "机关" Then
    Stujgboy = Stujgboy + Adodc1.Recordset.Fields("df").Value
    End If
    If Adodc1.Recordset.Fields("dw").Value = "后勤" Then
    Stuhqboy = Stuhqboy + Adodc1.Recordset.Fields("df").Value
    End If
    Adodc1.Recordset.MoveNext
    Wend
    '如下语句我想更改RECORDSOURC属性,使上面计算出的值存到另外一个表zf0中
    Adodc1.ConnectionString = "dsn=sport1"
    Adodc1.RecordSource = "select * from zf0"
    DataGrid1.ClearFields
    DataGrid1.ReBind
    Set DataGrid1.DataSource = Adodc1
    For i = 0 To 10
    Adodc1.Recordset.AddNew
    Adodc1.Recordset.Fields("dw") = "体育系"
    Adodc1.Recordset.Fields("cj") = stucj(i)
    Adodc1.Recordset.MoveNext
    Next
    Adodc1.Refresh
    End Sub
    从运行错误代码中可以看出,所做的操作还是针对SPORT表,就是说RECORDERSOURCE 属性没有变,请高手指点。谢谢!!!