以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- [求助]求助如果表名和列命名存在就替换之前的 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=147134) |
-- 作者:miaoqingqing -- 发布时间:2020/3/10 15:31:00 -- [求助]求助如果表名和列命名存在就替换之前的 For Each c As Col In CurrentTable.Cols Dim str As String For Each dc As Col In CurrentTable.Cols str = str & "," & dc.Name str = str .Trim(",") Dim fdr As DataRow = DataTables("表列名管理").Find("表名 = CurrentTable.name and 列名 In (" & str &")") If fdr Is Nothing Then Dim dr As DataRow = DataTables("表列名管理").AddNew dr("表名") = CurrentTable.name dr("列名") = c.Name dr("列宽") = c.Width Select Case c.DataCol.DataType.Name Case "String" If c.DataCol.MaxLength > 255 Then dr("类型") = "备注" Else dr("类型") = "字符" End If Case "DateTime" dr("类型") = "日期时间" Case "Boolean" dr("类型") = "逻辑" Case "Int32" dr("类型") = "整数" Case "Int16" dr("类型") = "短整数" Case "Byte" dr("类型") = "微整数" Case "Double" dr("类型") = "双精度" Case "Single" dr("类型") = "单精度" Case "Decimal" dr("类型") = "高精度" End Select End If Next Next 求助上面代码实现,如果表列名管理里的表名和列名已存在就不新增行,只是替换更新,表名列名列宽类型
|
-- 作者:有点蓝 -- 发布时间:2020/3/10 15:44:00 -- str = str & ",\'" & dc.Name & "\'" str = str .Trim(",") |
-- 作者:miaoqingqing -- 发布时间:2020/3/10 16:32:00 -- 按上楼修改后只能新增一行,辛苦群主再帮忙了 |
-- 作者:有点蓝 -- 发布时间:2020/3/10 17:05:00 -- 一个循环就够了 For Each c As Col In CurrentTable.Cols Dim fdr As DataRow = DataTables("表列名管理").Find("表名 = \'" & CurrentTable.name & "\' and 列名 = \'" & c.name & "\'") If fdr Is Nothing Then Dim dr As DataRow = DataTables("表列名管理").AddNew dr("表名") = CurrentTable.name dr("列名") = c.Name dr("列宽") = c.Width |