为了表达更直观,我在list中加了一些项目
比如list1中有:
年月
人数
出勤
产量
工效......
其中的年月对应数据库中TBData,人数对应PeopNum,出勤对应Duty,产量对应Uoutput,HourEff 对应工效等等,表是Wage2008
我想在Datagrid1中显示这些项目(根据list的选择),这个该怎么编写呢?
mySQL = "select TBData as 年月日期,Dept as 部门," & list1.Text & " from Wage2008  "
list1.text让它表示所选中的项。实在不会了,不知道怎么用SQL编写。

解决方案 »

  1.   

    dim i as integer
    dim cou as integer
    dim str1 as string
    cou = list1.ListCount
    for i=0 to cou-1
      if list1.Selected(i) then
        select case list1.List(i)
        case "年月"
           str1=str1 & ",TBData as " & list1.List(i)
        case "人数"
           str1=str1 & ",PeopNumas " & list1.List(i)
        case "出勤"
           str1=str1 & ",Dutyas " & list1.List(i)
        case "产量"
           str1=str1 & ",Uoutputas " & list1.List(i)
        case "工效"
           str1=str1 & ",HourEff as " & list1.List(i)
        end select
      end if
    nextif str1<>"" then
       str1=mid(str1,1)
       mySQL = "select " & str1 & " from Wage2008  "
    end if
      

  2.   

    当然,还有其它的办法,你还可以再加一个list2用来添加list1中对应字段名,这样就不需要select语句了
      

  3.   

    dim i as integer 
    dim cou as integer 
    dim str1 as string 
    cou = list1.ListCount 
    for i=0 to cou-1 
      if list1.Selected(i) then 
        select case list1.List(i) 
        case "年月" 
           str1=str1 & ",TBData as " & list1.List(i) 
        case "人数" 
           str1=str1 & ",PeopNumas " & list1.List(i) 
        case "出勤" 
           str1=str1 & ",Dutyas " & list1.List(i) 
        case "产量" 
           str1=str1 & ",Uoutputas " & list1.List(i) 
        case "工效" 
           str1=str1 & ",HourEff as " & list1.List(i) 
        end select 
      end if 
    next if str1 <> "" then 
       str1=mid(str1,1) 
       mySQL = "select " & str1 & " from Wage2008  " 
    end if 楼上正解