This topic is locked

Insert into a different data connection

5/18/2017 2:49:53 PM
ASPRunner.NET General questions
T
Tim author

Hi all,
I have an edit page that I'd like to use the built in event "Save old data record in a different table" but I'd like to insert it into a table that is in a different database on a different server (different data connection).
Here is the default event that comes from adding the built in event:
INSERT INTO AnotherTable (Field1, Field2) SELECT Field1, Field2 FROM " + GlobalVars.strTableName.ToString() + " where " + where.ToString()
How would I alter this to use a different data connection?
By the way, the different data connection I want to use is added to this project already on the "Tables" page of ASPR.
Thanks,

Tim

jadachDevClub member 5/18/2017

Try this:

string strSQLInsert = "Insert into AnotherTable (Field1) values ('" + oldvalues["Field1"].ToString() + "')";

GlobalVars.cman.byName("YOUR-CONNECTION-NAME").exec(strSQLInsert);
Obviously, you will need to create the new connection to the other database first within ASPRunner.net. You can then name that connection to whatever you want by right clicking it in the tree. That will be the name used in "YOUR-CONNECTION-NAME"

T
Tim author 5/19/2017

That's it! Thanks Jerry. You are invaluable asset to this forum!