Foxtable(狐表)用户栏目专家坐堂 → [求助]这段代码怎么改才行


  共有10352人关注过本帖树形打印复制链接

主题:[求助]这段代码怎么改才行

帅哥哟,离线,有人找我吗?
jianjingmaoyi
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:三尾狐 帖子:760 积分:4714 威望:0 精华:0 注册:2011/12/17 18:37:00
[求助]这段代码怎么改才行  发帖心情 Post By:2012/8/25 23:06:00 [显示全部帖子]

   我想把数据源1内的数据赚到数据源2   执行了,但是数据没有复制过去,应该咋改?  表是一模一样的结构.

Dim cmd As New SQLCommand
cmd.C o n n e c t i o n N a m e = "数据源1"
Dim cmd2 As New SQLCommand
cmd2.C o n n e c t i o n N a m e = "数据源2"
Dim dt As DataTable
Dim lst As List(Of String)
lst = Connections("数据源1").GetTableNames
For Each nm As String In lst
    cmd.CommandText = "SELECT * From {" & nm & " }"
    dt = cmd.ExecuteReader()
    For Each dr As DataRow In dt.DataRows
        For Each dc As DataCol In dt.DataCols
            cmd2.CommandText = "Insert Into " & nm & " (" & dc.Name & ") Values (" & dr(dc.Name) & ")"
            cmd2.ExecuteReader()
        Next
    Next
Next
MessageBox.Show("成功")
[此贴子已经被作者于2012-8-25 23:07:52编辑过]

 回到顶部
帅哥哟,离线,有人找我吗?
jianjingmaoyi
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:三尾狐 帖子:760 积分:4714 威望:0 精华:0 注册:2011/12/17 18:37:00
  发帖心情 Post By:2012/8/26 0:41:00 [显示全部帖子]

Dim d1 As Date = Date.Now
Dim cmd As New SQLCommand
cmd.C
Dim cmd2 As New SQLCommand
cmd2.C
Dim str1 As String, str2 As String
Dim dt As DataTable
Dim lst As List(Of String)
lst = Connections("数据源1").GetTableNames
For Each nm As String In lst
    cmd.CommandText = "SELECT * From {" & nm & " }"
    dt = cmd.ExecuteReader()
    For Each dr As DataRow In dt.DataRows
        str1= ""
        str2= ""
        For Each dc As DataCol In dt.DataCols
            If dc.IsString Then
                str1 = str1 & dc.name & ","
                str2 = str2 & "'" &  dr(dc.name) & "',"
            ElseIf dc.IsNumeric Then
                str1 = str1 & dc.name & ","
                str2 = str2 & "" &  dr(dc.name) & ","
                'ElseIf dc.IsDate Then
                
                '    str2 = str2 & "#" &  dr(dc.name) & "#,"
            End If
        Next
        str1 = str1.TrimEnd(",")
        str2 = str2.trimEnd(",")
        cmd2.CommandText = "Insert Into " & nm & " (" & str1 & ") Values (" & str2 & ")"
        cmd2.ExecuteReader()
    Next
Next
Dim d2 As Date = Date.Now
MessageBox.Show((d2-d1).Totalseconds)
MessageBox.Show("成功")

在群里弄了半天 数值和时间还有逻辑怎么转?字符型搞定了.

 回到顶部