combo2是显示 “系统”.combo3是“系统模块”
一个“系统”对应多个“系统模块”,有多个“系统”选项,当选择"系统"(combo2)某一项后,,combo3自动显示对应的“系统模块”的选项。
很奇怪的问题是,如果内容是数字比如1开头的话,明明数据是添加成功了,在数据库里也能看到刚才增加的数据,但在MSFlexGrid表格中“系统”一栏的内容是白板的。
但如果是手工输入内容,不管开头是什么,都能正常显示出来。“系统”与“系统模块”数据类型都是varchar下面是combo_Click的代码,“添加记录”的代码是没有问题的。因为如果我在combo2手动输入后再添加的话,MSFlexGrid显示是正常的。那有朋友能否帮我看下,怎样让MSFlexGrid表格中“系统”一栏的内容显示出来Private Sub Combo2_Click()
Dim cn As New ADODB.Connection                '定义数据库的连接
Dim rst As New ADODB.Recordset
cn.ConnectionString = "Provider=sqloledb;Data Source=OFFICE;Initial Catalog=h;User Id=sa;Password=123;"
cn.Open
rst.CursorLocation = adUseClient
rst.Open "select * from dataini_l where 系统='" & Combo2.Text & "'", cn, adOpenDynamic, adLockOptimistic
rst.MoveFirst
'--------------------------------------
Combo3.Clear
rst.MoveLast
rst.MoveFirst
  For i = 1 To rst.RecordCount
                 If rst.Fields("系统") <> "" Then
                    Combo3.AddItem rst.Fields("系统模块")
                    rst.MoveNext
                 End If
        Next
rst.Close
End Sub添加数据用:SQl = "insert into lzliu(负责人,区域,月份,系统,系统模块,[" & ComDate.Text & "],[" & ComDate.Text & "故障" & "]) values ('" & Text1.Text & "','" & Combo1.Text & "','" & txtMonth.Text & "','" & Combo2.Text & "','" & Combo3.Text & "','" & txtTime.Text & "','" & Text3.Text & "') select * from lzliu where 月份='" & txtMonth.Text & "' and 系统='" & Combo2.Text & "' and 系统模块='" & Combo3.Text & "'"cn.Execute (SQl)

解决方案 »

  1.   

    你没有说什么时候触发添加,也没说grid需要显示什么
      

  2.   

    将这段代码贴到combo2的dropdown事件中试试
      

  3.   

    SQl = "insert into lzliu(负责人,区域,月份,系统,系统模块,[" & ComDate.Text & "],[" & ComDate.Text & "故障" & "]) values ('" & Text1.Text & "','" & Combo1.Text & "','" & txtMonth.Text & "','" & Combo2.Text & "','" & Combo3.Text & "','" & txtTime.Text & "','" & Text3.Text & "') select * from lzliu where 月份='" & txtMonth.Text & "' and 系统='" & Combo2.Text & "' and 系统模块='" & Combo3.Text & "'" SQL 语句显然是错误的。Insert 语句有两种形式:Insert Into 表(字段名列表) Values(值表)Insert Into 表 Select <字段名列表> From 源表 ......你的语句中把两者混合了。
      

  4.   

    呵呵,没错的。
    问题已解决,多谢QQ好友mumu,不知此高手是否也在csdn