VB高手请进..VB查询SQL数据并计算问题
首先我用到了listview,ADO对象连接的SQL现在我卡在最后一步,计算了.
是这样,我需要对SQL的test表中的除了第一项以外,和后面的8项元素含量与text1.text中的内容相乘,并且显示在listview中,可是我发现我的思路越来越乱了,请教各位有没有什么办法,下面我贴下代码..
Command2为计算,表中有1.name 2.碳C 3.硅Si 4.锰Mn 5.硫S 6.磷P 7.铬Cr ....等等
数据库连接没有问题,现在就卡到计算了:
Private Sub Command2_Click()
If Text1.Text = "" Then
Else
cn.ConnectionString = "driver={sql server};server=192.168.0.27;uid=sa;pwd=sa;database=test"
cn.Open
rs.Open "select (C*'" & Text1.Text & "') from kesda where Name= '" & Combo2.Text & "' ", cn, adOpenKeyset, adLockPessimistic, adCmdText就是这里,如何计算表中的各项然后listview把结果反馈给我呢
rs.Close
ListView2.ListItems.Clear
End If
rs.Open
If rs.RecordCount > 0 Then
rs.MoveFirst
End If
Do While Not rs.EOF
Dim item1 As ListItem '第一列
Dim item2 As ListSubItem
....
....
Set item1 = ListView1.ListItems.Add(, , rs.Fields(0))
Set item2 = item1.ListSubItems.Add(, , rs.Fields(1))
....
后面的代码其实可以不用看,这些都是listview的和无关的
....
还有一个问题要请教大家,下面是代码
Private Sub Command1_Click()
cn.ConnectionString = "driver={sql server};server=192.168.0.27;uid=sa;pwd=sa;database=test"
cn.Open
If Combo1.Text = "" Then
MsgBox "对不起,请选择需要查询的元素!", vbOKOnly + vbExclamation, "提示"
Else
rs.Open "select * from kesda where Name = '" & Combo1.Text & "'", cn, adOpenKeyset, adLockPessimistic, adCmdText
rs.Close
ListView1.ListItems.Clear
我需要让紫色这里完成:在Combo1.text= "" 就是没有选择的时候,提示我MSGBOX..那个内容之后,不要执行下面的查询语句了,直接回到选择元素的那里,选择到元素了才去查询,不然每次都报错....各位大大,高手,大虾们...帮我瞅瞅呗.. --------------------编程问答-------------------- 表中有1.name 2.碳C 3.硅Si 4.锰Mn 5.硫S 6.磷P 7.铬Cr ....
***************************
表结构不清,说明一下
--------------------编程问答--------------------
Private Sub Command1_Click()--------------------编程问答--------------------
If Combo1.Text = "" Then
MsgBox "对不起,请选择需要查询的元素!", vbOKOnly + vbExclamation, "提示"
Else
cn.ConnectionString = "driver={sql server};server=192.168.0.27;uid=sa;pwd=sa;database=test"
cn.Open
rs.Open "select * from kesda where Name = '" & Combo1.Text & "'", cn, adOpenKeyset, adLockPessimistic, adCmdText
rs.Close
ListView1.ListItems.Clear
End If
End Sub
Private Sub Command1_Click()--------------------编程问答-------------------- Private Sub Command1_Click()
If trim(Combo1.Text & "") = "" Then
MsgBox "对不起,请选择需要查询的元素!", vbOKOnly + vbExclamation, "提示"
Else
cn.ConnectionString = "driver={sql server};server=192.168.0.27;uid=sa;pwd=sa;database=test"
cn.Open
rs.Open "select * from kesda where Name = '" & Combo1.Text & "'", cn, adOpenKeyset, adLockPessimistic, adCmdText
rs.Close
ListView1.ListItems.Clear
End If
End Sub
cn.ConnectionString = "driver={sql server};server=192.168.0.27;uid=sa;pwd=sa;database=test"
cn.Open
If Combo1.Text = "" Then
MsgBox "对不起,请选择需要查询的元素!", vbOKOnly + vbExclamation, "提示"
exit sub
Else
rs.Open "select * from kesda where Name = '" & Combo1.Text & "'", cn, adOpenKeyset, adLockPessimistic, adCmdText
rs.Close
ListView1.ListItems.Clear --------------------编程问答--------------------
--------------------编程问答-------------------- 不好意思...呵呵..
Private Sub Command1_Click()
cn.ConnectionString = "driver={sql server};server=192.168.0.27;uid=sa;pwd=sa;database=test"
cn.Open
If trim(Combo1.Text) = "" Then
MsgBox "对不起,请选择需要查询的元素!", vbOKOnly + vbExclamation, "提示"
Exit sub
Else
rs.Open "select * from kesda where Name = '" & trim(Combo1.Text) & "'", cn, adOpenKeyset, adLockPessimistic, adCmdText
rs.Close
ListView1.ListItems.Clear
--------------------编程问答--------------------
Private Sub Command1_Click()
cn.ConnectionString = "driver={sql server};server=192.168.0.27;uid=sa;pwd=sa;database=test"
cn.Open
If trim(Combo1.Text) = "" Then
MsgBox "对不起,请选择需要查询的元素!", vbOKOnly + vbExclamation, "提示"
Exit sub
Else
rs.Open "select * from kesda where Name = '" & trim(Combo1.Text) & "'", cn, adOpenKeyset, adLockPessimistic, adCmdText
rs.Close
ListView1.ListItems.Clear
end if
end sub
Private Sub Command1_Click()
If Combo1.Text = "" Then
MsgBox "对不起,请选择需要查询的元素!", vbOKOnly + vbExclamation, "提示"
Else
cn.ConnectionString = "driver={sql server};server=192.168.0.27;uid=sa;pwd=sa;database=test"
cn.Open
rs.Open "select * from kesda where Name = '" & Combo1.Text & "'", cn, adOpenKeyset, adLockPessimistic, adCmdText
rs.Close
ListView1.ListItems.Clear
end if
这个看着没什么错误呀.
补充:VB , 数据库(包含打印,安装,报表)