Last post Mar 31, 2017 12:27 AM by miltank09
Mar 28, 2017 10:52 PM|miltank09|LINK
Hi guys, I have a query which retrieves only 1 row and works good, I tried to assign that row into a variable in order to insert those data into another DB but I don't know how, I haven't found any information about this, I'm using VB as language and working
Mar 29, 2017 12:49 PM|Cathy Zou|LINK
For your problem,
1. You could store the row information in datatable.
2. Then you could use SqlBulkCopy.WriteToServer Method() to write the datatable to data table in a another database.
Something code as below:
string constr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
string Destinationconstr = ConfigurationManager.ConnectionStrings["DestinationConnectionString"].ConnectionString;
string query = "SELECT top 1 CategoryID, CategoryName,Description FROM Categories";
using (SqlConnection con = new SqlConnection(constr))
using (SqlCommand cmd = new SqlCommand(query,con))
using (SqlDataReader reader =cmd.ExecuteReader())
DataTable dt = new DataTable();
GridView1.DataSource = dt;
using(SqlBulkCopy bulkcopy=new SqlBulkCopy(Destinationconstr))
bulkcopy.DestinationTableName = "dbo.BulkCopyDemoMatchingColumns";
// Write from the source to the destination.
catch (Exception ex)
For more information. Please refer to the following links:
Mar 31, 2017 12:27 AM|miltank09|LINK
Thanks a lot, but I already solved it, I accessed each value of the row by the "Tables" and "Rows" property assigning them each one into a single variable, then I inserted in the dataTable desired :)