Dim n1 As Integer,str as stringstr = "选举中被选中的人数" + Chr(13) + Chr(10) + "单击确定"n1 = InputBox$(str, "请输入:", , 2500, 2500)adoStudent.RecordSource = "select TOP 'n1 ' * from can_info order by can_t desc"
 adoStudent.Refresh
 dgStudent.Refresh
怎么select 语句执行报错,“含有保留字或错误参数”
大侠救救小猫了

解决方案 »

  1.   

    adoStudent.RecordSource = "select TOP 'n1 ' * from can_info order by can_t desc"
    改为
    adoStudent.RecordSource = "select TOP " & n1 & " * from can_info order by can_t desc"应该先判断用户的输入是否有错Dim n1 As Integer,str as string
    dim strTemp as stringstr = "选举中被选中的人数" + Chr(13) + Chr(10) + "单击确定"strTemp = InputBox$(str, "请输入:", , 2500, 2500)
    n1=Val(strTemp)
    if n1<=0 then
       '提示重新输入
       exit sub
    end ifadoStudent.RecordSource = "select TOP " & n1 & " * from can_info order by can_t desc"
     adoStudent.Refresh
     dgStudent.Refresh