If cnn.State <> 0 Then
       cnn.Close
     End If
     Dim connectionstring As String
     connectionstring = connstr
     cnn.Open connectionstring
    Dim Sqlm As String
    Dim cx As String
      cx = Trim(Combo1.Text)
      If Combo1.Text <> "" Then
      Sqlm = cx & "=" & "'" & Trim(Combo1.Text) & "'"
    Else
      Sqlm = ""
    End If
    If cx = "报送信息学校" Then
    If Sqlm <> "" Then
       Sqlm = "select" & " " & cx & ",学籍号,姓名,性别,年龄,民族,籍贯,毕业学校,家庭住址,户口所在地,照顾类别,应往届,是否特长生,综合成绩" & " from Student_xx where " & Sqlm
    Else
       Sqlm = "select" & " " & cx & ",学籍号,姓名,性别,年龄,民族,籍贯,毕业学校,家庭住址,户口所在地,照顾类别,应往届,是否特长生,综合成绩" & "from Student_xx"
    End If
    End If
      rs.CursorLocation = adUseClient
      rs.Open Sqlm, cnn, adOpenKeyset, adLockPessimistic
      DataGrid1.AllowAddNew = False
      DataGrid1.AllowDelete = False
      DataGrid1.AllowUpdate = False
      Set DataGrid1.DataSource = rs
     DataGrid1.Columns(报送信息学校).Caption = "报送信息学校"
点查询后,老是在 rs.Open Sqlm, cnn, adOpenKeyset, adLockPessimistic提示第一行的“=”附近有错误?请高手指教。谢谢

解决方案 »

  1.   

    在rs.open 语句前 debug.print sqlm 看看有什么问题
      

  2.   

    where 后面的内容不对,会出现下面的结果
    Combo1.Text=Combo1.Text
      

  3.   

    帮你整理一下   If cnn.State  <> 0 Then cnn.Close 
       Dim connectionstring As String 
       Dim Sqlm As String 
       Dim cx As String    connectionstring = connstr 
       cnn.Open connectionstring 
       cx = Trim(Combo1.Text)
       If Sqlm  <> "" Then 
           '看你的程序好像是有“报送信息学校”这个字段,而且是字符串类型,
            '然后里面有可能是空也可能是“报送信息学校”值
           Sqlm = "select * from Student_xx where 报送信息学校='" & CX & "'" 
           '就算用你原来的写法也可以这样写,你的格式确实太乱了
           'Sqlm = "select " & cx & ",学籍号,姓名,性别,年龄,民族,籍贯,毕业学校,家庭住址," & _
           '       "户口所在地,照顾类别,应往届,是否特长生,综合成绩 " & _
           '       "from Student_xx where 报送信息学校='" & CX & "'"   Else 
           Sqlm = "select * from Student_xx" 
       End If    rs.CursorLocation = adUseClient 
       rs.Open Sqlm, cnn, adOpenKeyset, adLockPessimistic 
       DataGrid1.AllowAddNew = False 
       DataGrid1.AllowDelete = False 
       DataGrid1.AllowUpdate = False 
       Set DataGrid1.DataSource = rs 
       DataGrid1.Columns(报送信息学校).Caption = "报送信息学校"
      

  4.   

    你的Combo1.text内容到底是什么?
    你的sqlm与cx变量与Combo1.text是啥关联,你检查一下吧,似乎都乱套了.........If Combo1.Text  <> "" Then 
       cx = Trim(Combo1.Text) 
       If cx = "报送信息学校" Then 
          Sqlm = "select" & " " & cx & ",学籍号,姓名,性别,年龄,民族,籍贯,毕业学校,家庭住址,户口所在地,照顾类别,应往届,是否特长生,综合成绩" & " from Student_xx where 字段名=" & chr(39) & cx & chr(39)
       End If 
    End If