# Re: Answer for " DataEnvironment"

Posted by Spencer Yang on April 25, 1999 at 23:32:03:

In Reply to: Re: 急救 !! DataEnvironment posted by gg on April 24, 1999 at 22:42:48:

请参阅王国荣编着《visual Basic 6.0 资料库程式设计》第11章之deParm2.vbp

*** DataEnvironment1 设定如下

COMMAND1.TAB("内容")
出现下列鈙述
SELECT * FROM MYTABLE WHERE (FILED1 = ?)

COMMAND1.TAB("参数")
参数属性填列
.资料流入: 流入
.资料型态: adVariant(请视自己对资料定义选择)

***表单上有
Command1(按钮)
DataCombo11
Text1

Private Sub Command1_Click()
'先判断 command物件的资料录集合是否关闭中
If DataEnvironment1.rsCommand1.State <> adStateClosed Then
DataEnvironment1.rsCommand1.Close
End If
' 读取 Text2 设定给参数一
DataEnvironment1.Commands("Command1").Parameters(0) = Text1.Text
'DataEnvironment1.Commands("Command1").Parameters(1) = Text2.Text
Set DataCombo1.RowSource = DataEnvironment1
DataCombo1.RowMember = "Command1"
'结合显示栏位
DataCombo1.ListField = "AName"
End Sub

至于text1_keypress()怎么写，请比照comman1_click()
而dataCombo2如何由dataCombo1内容决定，只要将datacombo1的结果放置于label1之中(Visual=false),
datacombo2之作法则比煦上述作法即可。

Follow Ups: