c# - How to Insert Data on ServerA that comes from Select Data on ServerB? -
Scenario:
I have a development server, which allows me to insert data from my table with ServerB TableA I need to.
SERVERA.TableA: serialnumber = empty, partnumber = blank
ex:
database connection string 1 Select SerialNumber, partnumber from ServerB.TableA where (serialnumber = '1')
then
database connection string 2 < / P>
insert in serialnumber, partnumber
from SERVERA.TableA:
SERVERA.TableA: serialnumber = 1, Partnumber = 2
If you are using SQL Server, you can use the facility to provide convenience, you 'd be able to execute the following code on ServerB: < Pre>INSERT [dbo]. [Table] (Serial Number, Part Number) Select Serial Number, Partnumber FAR [Server A]. [Database Name ServerA] [DBO]. [Table] Where serial number = '1'
If you can not use linked servers, or it needs to be done in code, it is also quite simple: < / Var> connection query.Open (); Var query = "Selection serial number, Partnumber FDR [DBO]. [Table AA] where serial number = (Var adapter = new SqlDataAdapter (query, connection); {var data = new dataTable (); using adapter.fill (data); (var connection B = new SqlConnection (connectionStringForServerB) {var query = "INSERT INTO [dbo] [TABLE] A] (Serial Number, Partnumber) Value (@Surl, Part) "; foreach (DataRo recordforwards data in Rhodes) {(var command = new SQL command (query, connection b) {command.Parameters.AddWithValue (" @ Serial "Record FormSerA [" Serial Number "]); Command.Premium.AdvatValue (" Part @ ", RecordFormsServer [" Partnumber "]); Command.exquite NonCline ();}}}}}
There are more efficient ways to get involved, but the code is detected That is what I have done as I have done, it makes you clear how it works (it is worth noting that I did not really run which sample I have given, so it's a little bit Tweaking may be required, this is a Lso Sql server specific).
Comments
Post a Comment