Click here to Skip to main content
15,919,479 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi. I'd like to know a way to insert a row to a sql table from DataReader. Here's my code part that will do it:

C#
while (rdr2.Read())
                {
                    SqlCommand cmd3 = new SqlCommand(@"INSERT INTO DestinationDatabase.dbo."+ table.tableName ); //Problematic part
                    cmd3.ExecuteNonQuery();
                }

Note:This is a very simplistic code, i'm aware of injection vulnerability which i will fix later.
Thanks for your attention.
Posted
Updated 16-Sep-14 22:18pm
v4

1 solution

In this case you don't expect any values back, like from a SELECT query, so you should use
C#
cmd3.ExecuteNonQuery();


SqlCommand.ExecuteNonQuery Method[^]
 
Share this answer
 
Comments
YourAverageCoder 17-Sep-14 4:19am    
You're right.
George Jonsson 17-Sep-14 4:30am    
Then you can mark it as solved.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900