jruhe
asked on
VB6 - Updating SQL table from a non-SQL connection
Hello Experts,
I have a SQL database that I want to update with non-SQL information via an ODBC link. The link to the SQL database works, as well as the non-SQL link--they both work fine using something akin to the attached code (don't hold me to this--I distilled this from a larger spread of code, and I may be missing a dim or a set here or there, but the concept is what I am trying to get across--my originating code works). So here's the issue: If the client has, say, 50,000 records in their view, I don't want to have to hit SQL with 50,000 UPDATE commands. If both of my tables were native to SQL, I would like to do something like: UPDATE SqlTable Set Address = ClientTable.Address FROM SqlTable JOIN ClientTable ON SqlTable.ClientID = ClientTable.CustNo. However, they're not, and I have the attached code which is dog slow.
So. . . Any ideas? The data I'm updating is for a large accounting product--I'm not sure if i can do a SQL stored procedure, or even if it would work, but I can do a temporary SQL table; however, I imagine if I do 50,000 INSERTs, then one UPDATE, I'll have the same problem, except moved to another command.
The client date is not wide (maybe 3 fields--one key, two update fields); however, I think an array would not be indicated because I don't think I can Update a SQL table in VB using an array (other than one record at a time, circling right back to my problem).
Thanks
jr
I have a SQL database that I want to update with non-SQL information via an ODBC link. The link to the SQL database works, as well as the non-SQL link--they both work fine using something akin to the attached code (don't hold me to this--I distilled this from a larger spread of code, and I may be missing a dim or a set here or there, but the concept is what I am trying to get across--my originating code works). So here's the issue: If the client has, say, 50,000 records in their view, I don't want to have to hit SQL with 50,000 UPDATE commands. If both of my tables were native to SQL, I would like to do something like: UPDATE SqlTable Set Address = ClientTable.Address FROM SqlTable JOIN ClientTable ON SqlTable.ClientID = ClientTable.CustNo. However, they're not, and I have the attached code which is dog slow.
So. . . Any ideas? The data I'm updating is for a large accounting product--I'm not sure if i can do a SQL stored procedure, or even if it would work, but I can do a temporary SQL table; however, I imagine if I do 50,000 INSERTs, then one UPDATE, I'll have the same problem, except moved to another command.
The client date is not wide (maybe 3 fields--one key, two update fields); however, I think an array would not be indicated because I don't think I can Update a SQL table in VB using an array (other than one record at a time, circling right back to my problem).
Thanks
jr
' Client Data:
Dim cnnClient As ADODB.Connection
Dim sClientConnect As String
Dim strClientSQL As String
Dim rstClient As ADODB.Recordset
' SQL Data to be updated:
Dim strSql As String
Dim cmdUpdate As ADODB.Command
Dim sSqlConnect As String
' Client side setup
Set cnnClient = New ADODB.Connection
sClientConnect = "(Some successful yet proprietary ODBC connection string here)"
cnnClient.ConnectionString = sClientConnect
strClientSQL = "Select * from ClientView"
rstClient.Open strClientSQL, cnnClient, adOpenDynamic, adLockReadOnly
' SQL Data to be updated:
Set cmdUpdate = New ADODB.Command
sSqlConnect = "(Successful ODBC connection string here)"
cmdUpdate.ActiveConnection = sSqlConnect
' Scroll through client data & update the SQL data:
rstClient.MoveFirst
Do
strSql = "Update SqlTable Set Address = '" & rstClient.Fields("Address") & "' WHERE ClientID = '" & rstClient.Fields("CustNo") & "'"
cmdUpdate.CommandText = strSql
Loop While Not rstClient.EOF
Are you reading from the data source that is accessible via the odbc connection and writing to the sql database?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for these.
Kbirecki, I am indeed reading from the data source table that is accessible via the odbc connection and writing to the sql database. However, I'm worried about doing a CSV (I don't know where the server is in relation to the client machine, so I don't think I can give it a specific location).
Fomand, What kind of code is that? I'm trying to do this with VB6. . .
Thanks to both of you,
jr
Kbirecki, I am indeed reading from the data source table that is accessible via the odbc connection and writing to the sql database. However, I'm worried about doing a CSV (I don't know where the server is in relation to the client machine, so I don't think I can give it a specific location).
Fomand, What kind of code is that? I'm trying to do this with VB6. . .
Thanks to both of you,
jr
ASKER
One more thing: Can you write a VB array to a temporary table in SQL, without doing it line by line, or no?
Thanks again
Thanks again
>>Fomand, What kind of code is that?<<
It is called T-SQL (SQL dialect used by SQL Server). However, if you are still using SQL Server 2005 you will fast find that MERGE is not supported.
It is called T-SQL (SQL dialect used by SQL Server). However, if you are still using SQL Server 2005 you will fast find that MERGE is not supported.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Read my last comment. Thanks for the work-arounds, all of you! I'll let you know what worked when I get client feedback and, if it's still too slow, work with them using one of your solutions.