如何使用dt.copy方法将SQL适配器填充表复制到预先存在的表 [英] How do I use the dt.copy method to copy an SQL adapter filled table to a pre-existing table

查看:121
本文介绍了如何使用dt.copy方法将SQL适配器填充表复制到预先存在的表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要做的是将一个sql适配器填充表并将其复制到数据库中的预先存在的表中,或者创建一个新表并将其放入带有复制信息的数据库中。



这是我到目前为止。

What I am trying to do is take an sql adaptor filled table and copying it to either a preexisting table in a database or creating a new table and placing it into a database with the copied information.

here is what I have so far.

Dim sqlconn1 As New SqlConnection("connectionstring")

      Dim sqladaptor = New SqlDataAdapter
      sqlconn1.Open()
      sqladaptor.SelectCommand = New SqlCommand("select * from " + "[" + ListBox1.SelectedItem + "]", sqlconn1)

      sqladaptor.SelectCommand.ExecuteNonQuery()
      Dim dt As New DataTable

      sqladaptor.Fill(dt)

      sqlconn1.Close()


      dt.TableName = "CopyTable"
     ??????? = dt.Copy()

      sqlconn2.Close()





什么我试过了:



我试图创建另一个新表。它注册了数据但不会附加到数据库。我需要做的不仅仅是从我需要在另一个数据库中使用它的副本中读取数据。



What I have tried:

I have tried to create another new table. it registered the data but would not attach to a database. I need to do more than just read the data from a copy I need to use it in another database.

推荐答案

复制DataTable对象不会得到任何东西所有。



如有必要,您必须首先执行查询以在数据库中创建表。我不知道你的要求不是很清楚。



一旦表存在,你必须通过DataTable对象并执行一个SQL INSERT或者根据你的模糊要求对该表进行UPDATE查询。



你可以使用另一个SqlDataAdapter,但我从来没有这样做过。我只是编写代码来自己处理操作。
Copying the DataTable object doesn't get you anything at all.

You have to first execute a query to create the table in the database, if necessary. I have no idea as your "requirements" are not very clear.

Once the table is there, you have to go through the DataTable object and execute either an SQL INSERT or UPDATE query against that table, again, depending on your vague requirements.

You COULD use another SqlDataAdapter for this, but I never do. I just write the code to handle the operation myself.


这篇关于如何使用dt.copy方法将SQL适配器填充表复制到预先存在的表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆