以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  加载GUID字段  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=108138)

--  作者:home8225
--  发布时间:2017/10/17 10:42:00
--  加载GUID字段

直接调用原数据库的GUID字段作为唯一性判断,但是加载不进来,报错,求助。。。


图片点击可在新窗口打开查看此主题相关图片如下:qq截图20171014193252.png
图片点击可在新窗口打开查看

Dim cmd As New SQLCommand

Dim dt As DataTable

Dim sCols() As String = {"ID","备注","公司品号","公司品名", "公司材质", "公司规格", "公司图号","单据日期","供应类型", "项目单位","客户型号", "客户品名", "客户单号","销售单号","订单数量","客户材质"}

Dim dCols() As String = {"ID","备注","公司品号","公司品名", "公司材质", "公司规格", "公司图号","单据日期","供应类型", "项目单位","客户型号", "客户品名", "客户单号","销售单号","订单数量","客户材质"}

cmd.C

cmd.CommandText = "Se/ect  {SALES_DELIVERY}.[DOC_NO] As [预备发货单号],{SALES_ORDER_DOC_D}.REMARK As [备注],[ITEM_CODE] As [公司品号],[ITEM_NAME] As [公司品名],SHORTCUT As [公司材质],{ITEM}.[ITEM_SPECIFICATION] As [公司规格],[DRAWING_NO] As [公司图号],CONVERT(varchar(16),{SALES_DELIVERY}.[DOC_DATE], 23) As [单据日期],{SALES_ORDER_DOC_D}.UDF021 As [供应类型],{SALES_ORDER_DOC_D}.UDF024 As [项目单位],{SALES_ORDER_DOC_D}.UDF025 As [客户型号],{SALES_ORDER_DOC_D}.UDF026 As [客户品名],[CUSTOMER_ORDER_NO] As [客户单号],{SALES_ORDER_DOC}.[DOC_NO] As [销售单号],{SALES_ORDER_DOC_D}.UDF022 As [客户材质],{SALES_ORDER_DOC_D}.[BUSINESS_QTY] As [订单数量],{SALES_DELIVERY_D}.SequenceNumber As [序号],{SALES_ORDER_DOC_D}.[SALES_ORDER_DOC_D_ID] As [ID] From (((({SALES_ORDER_DOC_D} Left JOIN {SALES_ORDER_DOC} ON {SALES_ORDER_DOC}.[SALES_ORDER_DOC_ID] = {SALES_ORDER_DOC_D}.[SALES_ORDER_DOC_ID]) Left JOIN {SALES_ORDER_DOC_SD} ON {SALES_ORDER_DOC_SD}.[SALES_ORDER_DOC_D_ID] = {SALES_ORDER_DOC_D}.[SALES_ORDER_DOC_D_ID]) Left JOIN {SALES_DELIVERY_D} ON {SALES_DELIVERY_D}.[REFERENCE_SOURCE_ID_ROid] = {SALES_ORDER_DOC_SD}.[SALES_ORDER_DOC_SD_ID]) Left JOIN {SALES_DELIVERY} ON {SALES_DELIVERY}.[SALES_DELIVERY_ID] = {SALES_DELIVERY_D}.[SALES_DELIVERY_ID]) Inner JOIN {ITEM} ON {ITEM}.[ITEM_BUSINESS_ID] = {SALES_ORDER_DOC_D}.[ITEM_ID]"

dt = cmd.ExecuteReader()

For Each dr As DataRow In dt.DataRows

Dim t As DataRow= DataTables("销售订单测试").Find("[ID] = \'" & dr(sCols(0)) & "\'") 


    If t Is Nothing Then \'如果不存在同编号的订单

    t = DataTables("销售订单测试").AddNew()

    For i As Integer =0 To sCols.Length -1

        t(dCols(i)) = dr(sCols(i))

    Next

    End If

Next



--  作者:有点甜
--  发布时间:2017/10/17 10:51:00
--  

改成

 

Dim t As DataRow= DataTables("销售订单测试").Find("[ID] = \'" & dr(sCols(0)).ToString() & "\'") 


--  作者:home8225
--  发布时间:2017/10/17 20:13:00
--  
报错:
从类型“Guid”到类型“String”的转换无效。


--  作者:home8225
--  发布时间:2017/10/17 20:28:00
--  
能够加载1条,但是仍然报错...

图片点击可在新窗口打开查看此主题相关图片如下:测.jpg
图片点击可在新窗口打开查看

图片点击可在新窗口打开查看此主题相关图片如下:测1.jpg.jpg
图片点击可在新窗口打开查看

Dim t As DataRow= DataTables("销售订单测试").Find("[ID] = \'" & dr(sCols(0)).ToString() & "\'") 
    If t Is Nothing Then \'如果不存在同编号的订单
    t = DataTables("销售订单测试").AddNew()

        t(dCols(0)) = dr(sCols(0)).ToString() 
    For i As Integer =1 To sCols.Length -1
        t(dCols(i)) = dr(sCols(i))


    Next
    End If
Next


把代码改成下面这样的话就能不断加载,但是每加载一条就会弹一次窗,求怎么解决。。

图片点击可在新窗口打开查看此主题相关图片如下:测.jpg
图片点击可在新窗口打开查看
Dim t As DataRow= DataTables("销售订单测试").Find("[ID] = \'" & dr(sCols(0)).ToString() & "\'") 
    If t Is Nothing Then \'如果不存在同编号的订单
    t = DataTables("销售订单测试").AddNew()
    For i As Integer =1 To sCols.Length -1
        t(dCols(0)) = dr(sCols(0)).ToString() 
    Next
    End If
Next

[此贴子已经被作者于2017/10/17 20:32:11编辑过]

--  作者:有点蓝
--  发布时间:2017/10/17 20:31:00
--  
2个表对应的的列的类型不一致吧

For i As Integer =1 To sCols.Length -1
if dr.isnull(sCols(i)) = false then
        t(dCols(i)) = dr(sCols(i))
end if

    Next