VB中在数据库把数据库中的一个值返回到窗体的text中。程序怎么编?
数据库的地址:D:\毕业设计\数据库\订单估算成本.mdb。段名为:产品单价。这是之前的程序,但是运行不了……求高手指教哈……PrivateSubCommand1_Cli...
数据库的地址:D:\毕业设计\数据库\订单估算成本.mdb。段名为:产品单价。这是之前的程序,但是运行不了……求高手指教哈……
Private Sub Command1_Click()
Dim cn As ADODB.Connection
Dim rs1 As ADODB.Recordset
Dim tsql1 As String
Set cn = New ADODB.Connection
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\毕业设计\数据库\订单估算成本.mdb;Persist Security Info=False"
Set rs1 = New ADODB.Recordset
tsql1 = "select sum(产品单价) from 订单估算成本 where 车型 = Combo1.Text and 翻转机构 = Combo2.Text and 箱体材质 = Combo3.Text"
rs1.Open tsql1, cn, adOpenKeyset, adLockPessimistic
Text1.Text = rs1(0)
End Sub 展开
Private Sub Command1_Click()
Dim cn As ADODB.Connection
Dim rs1 As ADODB.Recordset
Dim tsql1 As String
Set cn = New ADODB.Connection
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\毕业设计\数据库\订单估算成本.mdb;Persist Security Info=False"
Set rs1 = New ADODB.Recordset
tsql1 = "select sum(产品单价) from 订单估算成本 where 车型 = Combo1.Text and 翻转机构 = Combo2.Text and 箱体材质 = Combo3.Text"
rs1.Open tsql1, cn, adOpenKeyset, adLockPessimistic
Text1.Text = rs1(0)
End Sub 展开
1个回答
展开全部
修改:tsql1 = "select sum(产品单价) from 订单估算成本 where 车型 = Combo1.Text and 翻转机构 = Combo2.Text and 箱体材质 = Combo3.Text"
为:
tsql1 = "select sum(产品单价) from 订单估算成本 where 车型='" & Combo1.Text & "' and 翻转机构='" & Combo2.Text & "' and 箱体材质='" & Combo3.Text & "'"
楼主试试看
为:
tsql1 = "select sum(产品单价) from 订单估算成本 where 车型='" & Combo1.Text & "' and 翻转机构='" & Combo2.Text & "' and 箱体材质='" & Combo3.Text & "'"
楼主试试看
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询