Find Code:
All Words
Any of the Words
Exact Phrase
Home
:
Code
:
Forums
:
Submit
:
Mailing List
:
About
:
Contact
Code
All
VB.NET
ASP.NET
C#
VB Classic
ASP Classic
Snippets
Popular
Resources
Submit Code
Forums
Articles
Tips
Links
Books
Contest
Link to us
This script allow to load data between two data ba...
Author:
Santi Mondejar
E-mail:
Click to e-mail author
Submitted:
8/3/2000
Version:
ASP
Compatibility:
ASP
Category:
ASP
Views:
21766
This script allow to load data between two data bases on line. It opens two parallel connections, and it synchronizes two recorset that works in the two data base, reading in one, and writing in the other. Simply, the name of the origin table must be indicated, as well as odbc dsn of each data bases. This example works with two Access data bases without dsn, although in fact I use script to load data in a Oracle system from a data base Access via odbc.
Declarations:
Code:
<% Dim tbl 'table name tbl="some_table" 'Opening Database 1. Set db_cnx1 = Server.CreateObject("ADODB.Connection") db_path="DBQ=" & server.mappath("db1.mdb") db_cnx1.Open "DRIVER={Microsoft Access Driver (*.mdb)}; " & db_path sql1="Select * from " & tbl on error resume next Set db_rcdst1=db_cnx1.execute(sql1) 'Opening Database 2 Set db_cnx2=server.createobject("adodb.connection") db_path="DBQ=" & server.mappath("db2.mdb") db_cnx2.Open "DRIVER={Microsoft Access Driver (*.mdb)}; " & db_path 'Starting table & recorsets iteraction db_rcdst1.MoveFirst all_flds = db_rcdst1.Fields.Count-1 all_records = 0 db_cnx2.BeginTrans Do While Not db_rcdst1.EOF all_records=all_records+1 Sqlz="" For nCounter=0 to all_flds current_value = db_rcdst1(nCounter) If IsNull(current_value) Then current_value=Chr(32) If VarType(current_value) > 6 Then Sqlz=Sqlz & Chr(39) & current_value & "'," Else current_value=Replace(current_value, Chr(44), Chr(46) ) Sqlz=Sqlz & current_value & "," End If Next a = Left(Sqlz, Len(Sqlz)-1) sql1="Insert Into " & tbl & " values(" & a & ")" Set db_rcdst2=db_cnx2.execute(sql1) db_rcdst1.movenext loop If db_cnx2.Errors.Count = 0 Then db_cnx2.CommitTrans Response.Write"
" Response.Write all_records & " rows inserted in destiny." Else db_cnx2.RollbackTrans Response.Write " Unexpected error. Operation canceled" End If db_cnx2.close set db_cnx2=nothing db_cnx1.close set db_cnx1 = nothing %>
Home
|
Forums
|
Submit
|
Books
|
Mailing List
|
Advertising
|
About
|
Contact
© 2024 A1VBCode. All rights reserved.
Legal disclaimer & terms of use
Privacy statement