在 vb.net 中插入 INTO

发布于 2024-09-10 03:44:57 字数 106 浏览 3 评论 0原文

我有2个数据库。第一个我有 10 张桌子。第二个只有1张桌子。我想从第一个数据库的每个表中选择 1 列,然后插入另一个数据库。如何使用 VB.net 中的 INSERT INTO 语句来管理此问题?

I have 2 databases. In first one I have 10 tables. Second one is only 1 table. I would like to select 1 columns from each table from 1st database and Insert INTO another database. How can I manage this using INSERT INTO statement in VB.net?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

放手` 2024-09-17 03:44:57

我删除了之前的答案,说你必须手动复制数据。现在,我们假设您想使用 SELECT INTO 语句来执行此操作。

以下代码显示如何使用 ADO.NET 连接和命令对象在数据库上执行 SQL 命令:

' Open a connection to your database (e.g. in a SQL Server): '
Using connection As IDbConnection = New SqlConnection("<Connection string>")
    connection.Open()
    Try

        ' Define the SQL command to be executed here: '
        Dim command As IDbCommand = connection.CreateCommand()
        command.CommandText = "SELECT <...> INTO <...>"

        ' Execute the command: '
        command.ExecuteNonQuery()

    Finally
        connection.Close()
    End Try
End Using

I deleted my previous answer saying that you have to manually copy over the data. For now, let's assume you want to do this with a SELECT INTO statement.

The following code shows you how to execute a SQL command on your database using a ADO.NET connection and command object:

' Open a connection to your database (e.g. in a SQL Server): '
Using connection As IDbConnection = New SqlConnection("<Connection string>")
    connection.Open()
    Try

        ' Define the SQL command to be executed here: '
        Dim command As IDbCommand = connection.CreateCommand()
        command.CommandText = "SELECT <...> INTO <...>"

        ' Execute the command: '
        command.ExecuteNonQuery()

    Finally
        connection.Close()
    End Try
End Using
岁吢 2024-09-17 03:44:57

我希望这会有所帮助:

从 sql 方面,您只需要编写一个存储过程来插入(十个)哈希表,然后选择/将它们插入到目标表中。

在 Vb.net 中,您需要:一个连接对象和一个命令对象来调用您的存储过程

I hope this helps:

From sql side, you'll just need to write a stored procedure to insert into (ten) hash tables and select/insert them into your target table.

In Vb.net, you'll need: a connection object and a command object to call your stored procedure

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文