Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27034

VS 2012 Insert DATATABLE into SQL

$
0
0
Good morning,
I'm a problem with my VB.Net and SQL.
My test code is:
Code:

Dim ConexaoRcsoft, ConexaoDB As SqlConnection
        Dim DsDados As DataSet
        Dim Dt As DataTable

        Dim sqlString As String = "SELECT taxa,descricao FROM dbo.taxa"
        ConexaoRcSoft = New SqlConnection(connStrinRcSoft)
        ConexaoDB = New SqlConnection(connString)

        Dim AdaptadorDados As SqlDataAdapter = New SqlDataAdapter(sqlString, ConexaoRcsoft)
        DsDados = New DataSet()
        AdaptadorDados.Fill(DsDados, "taxa")

        Dt = DsDados.Tables("taxa")

        ConexaoDB.Open()
        Dim sc As New SqlCommand(
        "INSERT INTO dbo.teste (taxa, descricao)" &
            "SELECT taxa, descricao FROM @taxa;", ConexaoDB)
        sc.Parameters.AddWithValue("@taxa", DsDados)
        sc.ExecuteNonQuery()
        MsgBox(Dt.Rows.Count)
        ConexaoDB.Close()

I get the values from one SQL SERVER, using conexaoRcsoft
Then, I need insert one ore more tables into another SQL SERVER, using the conexaoBD.
Can I insert the dataset or datatable into my new SQL server database?
How???

The server are the same, but the databases are diferent.

I try many solutions, but none of them works

Viewing all articles
Browse latest Browse all 27034

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>