VB高手进,解决Datacombo与TextBox问题!
请教高手我SQLSERVER2000中有张课程表,字段有课程名称、课程单价等我现在想用datacombo控件从表中读出课程名称,同时选中某课程时,在旁边的TEXTBOX控...
请教高手
我SQL SERVER 2000中有张课程表,字段有课程名称、课程单价等
我现在想用datacombo控件从表中读出课程名称,同时选中某课程时,在旁边的TEXTBOX控件中读出该课程对应的单价,想问高手,如何用代码实现!!
谢谢,如方法正确,赏分继续加~
我是想做课程配置成套餐,也就是说我有5个datacombo控件,都是读取同一个ADO控件绑定的课程表,每个DataCombo控件读出的课程可以不同,所以也就对应了旁边的text显示的单价不同~
一楼的答案好像不是太合适~ 展开
我SQL SERVER 2000中有张课程表,字段有课程名称、课程单价等
我现在想用datacombo控件从表中读出课程名称,同时选中某课程时,在旁边的TEXTBOX控件中读出该课程对应的单价,想问高手,如何用代码实现!!
谢谢,如方法正确,赏分继续加~
我是想做课程配置成套餐,也就是说我有5个datacombo控件,都是读取同一个ADO控件绑定的课程表,每个DataCombo控件读出的课程可以不同,所以也就对应了旁边的text显示的单价不同~
一楼的答案好像不是太合适~ 展开
2个回答
展开全部
这是我以前做的一个课程设计的代码中的一部分,和你要实现的功能类似,是选择一个设备类型,另一个datacombo中自动查询出对应类型的设备名称,再选择设备类型自动查询出设备型号...
控件是一个DataCombo对应有一个Adodc控件。自己看一下吧,vb很简单。
'选择 设备类型 触发事件
Private Sub DataCombo_Sort_Change()
Adodc1.Recordset.Bookmark = DataCombo_Sort.SelectedItem
Adodc2.ConnectionString = ConnStr
Adodc2.RecordSource = "select * from EquipmentName where SortCode='" + Adodc1.Recordset.Fields("SortCode") + "'"
Adodc2.Refresh
With DataCombo_Name
.Text = ""
Set .RowSource = Adodc2
.ListField = "EquipmentName"
.Refresh
End With
Call DataCombo_Name_Change
End Sub
'选择 设备名称 触发事件
Private Sub DataCombo_Name_Change()
If DataCombo_Name.Text = "" Then
DataCombo_Mode.Text = ""
Set DataCombo_Mode.RowSource = Nothing
DataCombo_Mode.Refresh
Exit Sub
End If
Adodc2.Recordset.Bookmark = DataCombo_Name.SelectedItem
Adodc3.ConnectionString = ConnStr
Adodc3.RecordSource = "select * from EquipmentMode where EquipmentNameNo=" + CStr(Adodc2.Recordset.Fields("EquipmentNameNo"))
Adodc3.Refresh
With DataCombo_Mode
.Text = ""
Set .RowSource = Adodc3
.ListField = "EquipmentMode"
.Refresh
End With
End Sub
'选择 设备型号 触发事件
Private Sub DataCombo_Mode_Change()
If DataCombo_Mode.Text = "" Then
Set DataCombo_Query.RowSource = Nothing
DataCombo_Query.Refresh
Exit Sub
End If
Adodc3.Recordset.Bookmark = DataCombo_Mode.SelectedItem
Adodc4.ConnectionString = ConnStr
Adodc4.RecordSource = "select * from Malfunction where EquipmentModeNo=" + CStr(Adodc3.Recordset.Fields("EquipmentModeNo"))
Adodc4.Refresh
With DataCombo_Query '在查询框中添加已有故障以方便用户输入
Set .RowSource = Adodc4
.ListField = "MalfunctionDescription"
.Refresh
End With
End Sub
'点击 故障列表 选择了一种故障
Private Sub DataList_Dscrip_Click()
If DataList_Dscrip.Text = "" Then
DataList_Dscrip.Text = ""
Set DataList_Reason.RowSource = Nothing
DataList_Reason.Refresh
Exit Sub
End If
Text_Dscrip.Text = DataList_Dscrip.Text '在文本框中显示 故障原因 详情
Text_Reason.Text = ""
Text_Resolvent.Text = ""
Adodc5.Recordset.Bookmark = DataList_Dscrip.SelectedItem
Adodc6.ConnectionString = ConnStr
Adodc6.RecordSource = "Query_Malfunction " + CStr(Adodc3.Recordset.Fields("EquipmentModeNo")) + ",'" + Trim(DataList_Dscrip.Text) + " '"
Adodc6.Refresh
Set DataList_Reason.RowSource = Adodc6 '初始化 解决方法 列表
DataList_Reason.ListField = "Reason"
DataList_Reason.Refresh
End Sub
'点击 故障原因列表 在文本框中显示 故障原因和解决方法 详情
Private Sub DataList_Reason_Click()
If DataList_Reason.Text = "" Then
Text_Reason.Text = ""
Text_Resolvent.Text = ""
Exit Sub
End If
Text_Reason.Text = DataList_Reason.Text '在文本框中显示 故障原因 详情
Adodc6.Recordset.Bookmark = DataList_Reason.SelectedItem
' Adodc6.Refresh
Text_Resolvent.Text = Adodc6.Recordset.Fields("Resolvent") '在文本框中显示 解决方法 详情
End Sub
控件是一个DataCombo对应有一个Adodc控件。自己看一下吧,vb很简单。
'选择 设备类型 触发事件
Private Sub DataCombo_Sort_Change()
Adodc1.Recordset.Bookmark = DataCombo_Sort.SelectedItem
Adodc2.ConnectionString = ConnStr
Adodc2.RecordSource = "select * from EquipmentName where SortCode='" + Adodc1.Recordset.Fields("SortCode") + "'"
Adodc2.Refresh
With DataCombo_Name
.Text = ""
Set .RowSource = Adodc2
.ListField = "EquipmentName"
.Refresh
End With
Call DataCombo_Name_Change
End Sub
'选择 设备名称 触发事件
Private Sub DataCombo_Name_Change()
If DataCombo_Name.Text = "" Then
DataCombo_Mode.Text = ""
Set DataCombo_Mode.RowSource = Nothing
DataCombo_Mode.Refresh
Exit Sub
End If
Adodc2.Recordset.Bookmark = DataCombo_Name.SelectedItem
Adodc3.ConnectionString = ConnStr
Adodc3.RecordSource = "select * from EquipmentMode where EquipmentNameNo=" + CStr(Adodc2.Recordset.Fields("EquipmentNameNo"))
Adodc3.Refresh
With DataCombo_Mode
.Text = ""
Set .RowSource = Adodc3
.ListField = "EquipmentMode"
.Refresh
End With
End Sub
'选择 设备型号 触发事件
Private Sub DataCombo_Mode_Change()
If DataCombo_Mode.Text = "" Then
Set DataCombo_Query.RowSource = Nothing
DataCombo_Query.Refresh
Exit Sub
End If
Adodc3.Recordset.Bookmark = DataCombo_Mode.SelectedItem
Adodc4.ConnectionString = ConnStr
Adodc4.RecordSource = "select * from Malfunction where EquipmentModeNo=" + CStr(Adodc3.Recordset.Fields("EquipmentModeNo"))
Adodc4.Refresh
With DataCombo_Query '在查询框中添加已有故障以方便用户输入
Set .RowSource = Adodc4
.ListField = "MalfunctionDescription"
.Refresh
End With
End Sub
'点击 故障列表 选择了一种故障
Private Sub DataList_Dscrip_Click()
If DataList_Dscrip.Text = "" Then
DataList_Dscrip.Text = ""
Set DataList_Reason.RowSource = Nothing
DataList_Reason.Refresh
Exit Sub
End If
Text_Dscrip.Text = DataList_Dscrip.Text '在文本框中显示 故障原因 详情
Text_Reason.Text = ""
Text_Resolvent.Text = ""
Adodc5.Recordset.Bookmark = DataList_Dscrip.SelectedItem
Adodc6.ConnectionString = ConnStr
Adodc6.RecordSource = "Query_Malfunction " + CStr(Adodc3.Recordset.Fields("EquipmentModeNo")) + ",'" + Trim(DataList_Dscrip.Text) + " '"
Adodc6.Refresh
Set DataList_Reason.RowSource = Adodc6 '初始化 解决方法 列表
DataList_Reason.ListField = "Reason"
DataList_Reason.Refresh
End Sub
'点击 故障原因列表 在文本框中显示 故障原因和解决方法 详情
Private Sub DataList_Reason_Click()
If DataList_Reason.Text = "" Then
Text_Reason.Text = ""
Text_Resolvent.Text = ""
Exit Sub
End If
Text_Reason.Text = DataList_Reason.Text '在文本框中显示 故障原因 详情
Adodc6.Recordset.Bookmark = DataList_Reason.SelectedItem
' Adodc6.Refresh
Text_Resolvent.Text = Adodc6.Recordset.Fields("Resolvent") '在文本框中显示 解决方法 详情
End Sub
参考资料: 原创
金山毒霸
2024-10-31 广告
2024-10-31 广告
大部分系统错误,是因为某些DLL文件丢失造成的,比如未安装DirectX9或DirectX 9.0组件已损坏、缺少Visual C ++库、未安装.net库。解决方法如下:一、 手动解决方法1、先确定电脑操作系统是多少位的,现在的电脑一般都...
点击进入详情页
本回答由金山毒霸提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询