|
-
Jun 12th, 2013, 10:21 AM
#1
Thread Starter
Hyperactive Member
Insert DATATABLE into SQL
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
-
Jun 12th, 2013, 10:24 AM
#2
Thread Starter
Hyperactive Member
Re: Insert DATATABLE into SQL
In this case, the error is:
"No mapping exists from object type System.Data.DataSet to a known managed provider native type."
-
Jun 12th, 2013, 03:39 PM
#3
Re: Insert DATATABLE into SQL
I assume that dbo.teste is the database itself in which case INSERT is inapplicable. To transfer a table to a new database you will first have to CREATE a table with a matching schema in the new database and then INSERT the values into the table.
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
Jun 12th, 2013, 05:23 PM
#4
Thread Starter
Hyperactive Member
Re: Insert DATATABLE into SQL
Hi.
The dbo.taxa is my source table at my source database
And the dbo.teste is my destination table at my destination database.
the server is the same, but have two databases. And teh tables (source and destination) are equal.
-
Jun 12th, 2013, 05:39 PM
#5
Re: Insert DATATABLE into SQL
Ok. Not sure that I really understand why you're getting that particular error then but moving on.
"INSERT INTO dbo.teste (taxa, descricao)" &
"SELECT taxa, descricao FROM @taxa;", ConexaoDB)
The syntax here is wrong. See http://www.w3schools.com/sql/sql_select_into.asp
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
Jun 12th, 2013, 06:05 PM
#6
Thread Starter
Hyperactive Member
Re: Insert DATATABLE into SQL
It's wrong WHY?
It's the only way for inject my dataset/datatable in the SQL statement.
This, is the only think I wanna do. Insert onde dataset/datatable to a SQL Database
-
Jun 12th, 2013, 06:20 PM
#7
Re: Insert DATATABLE into SQL
Did you even bother to read the page I pointed you to? It's wrong because it's wrong!
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
Jun 12th, 2013, 06:23 PM
#8
Thread Starter
Hyperactive Member
Re: Insert DATATABLE into SQL
Sorry, but the SQL was not wrong.
-
Jun 12th, 2013, 06:25 PM
#9
Hyperactive Member
Re: Insert DATATABLE into SQL
select * into newTable from OldDatabase.dbo.OldTable
-
Jun 13th, 2013, 03:57 AM
#10
Thread Starter
Hyperactive Member
Re: Insert DATATABLE into SQL
Hi.
In this case I cant access the old database directly.
This, cause first I need pass the data to a dataset, work them, and only after the upates, inject the data no the new database
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|