-- 作者:yankunhao
-- 发布时间:2013/10/24 10:27:00
-- 关于SOL语句的合成问题
在设计过程中加入下面的代码,但在测试时发现一连串的提示出错,查不清楚是什么原因:
Dim cmd6 As new sqlcommand cmd6.C Dim dt1 As DataTable Dim ps As List(Of String) Dim ids1 As String cmd6.CommandText = "select part_no from {cpcbsj}" ’ 这里想要的是选择出cpcbsj表中的所有产品编号,cpcbsj是另一个数据源 的
dt1 = cmd6.ExecuteReader() For Each dr6 As DataRow In dt1.DataRows ids1 = ids1 & ",\'" & dr6("part_no") & "\'" Next ids1 = ids1.Trim(",") ids1 = "(" & ids1 & ")" MessageBox.Show("a" & ids1) \' 发现这里的ids1能返回正确的字符 Dim cmd3 As New SQLCommand cmd3.C Dim dt As DataTable Dim ids As String cmd3.CommandText = "select parent_part from {obom_stru2} where child_part = \'" & e.DataRow("child_part") & "\' And parent_part In " & ids1 \' 这里想要的是选择出当前修改的BOM的单价,且产品编码都在上面选择出的编码内的。 dt = cmd3.ExecuteReader() For Each dr1 As DataRow In dt.DataRows ids = ids & ",\'" & dr1("parent_part") & "\'" ’这里已能选出所有所要更新的产品编码 Next ids = ids.Trim(",") ids = "(" & ids & ")" MessageBox.Show("b" & ids) ‘这里返回的字符也正确 For Each s1 As String In ids ’ 这里是想对所选出的编码产品逐一进行BOM总价更新 MessageBox.Show("bb" & s1) ’ 但这里第一出反回的是“(”,真奇怪,第二次出现的是 "\'" Dim cmd4 As New SQLCommand Dim zj1 As Decimal cmd4.C cmd4.CommandText ="Select sum(bom_cbdj) As BOM总价 from {obom_stru2} INNER JOIN obas_part1 on {obom_stru2}.child_part = {obas_part1}.part_no where parent_part= \'" & s1 & "\'" zj1 = cmd4.ExecuteScalar() Dim cmd5 As New SQLCommand cmd5.C cmd5.CommandText = "UPDATE {cpcbsj} SET [cpcbb] = " & zj1 & " Where [part_no] = \'" & s1 & "\'" cmd5.ExecuteNonQuery() Next
测试过程中发现下面的提示信息:
此主题相关图片如下:1.png

此主题相关图片如下:2.png

此主题相关图片如下:3.png

此主题相关图片如下:4.png

此主题相关图片如下:5.png

此主题相关图片如下:6.png

[此贴子已经被作者于2013-10-24 10:54:15编辑过]
|