Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB How-To
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
VB How-To Ask your "How do I do this with VB?" questions in this forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 6th, 2011, 03:37 PM
Friend of Wrox
Points: 1,035, Level: 12
Points: 1,035, Level: 12 Points: 1,035, Level: 12 Points: 1,035, Level: 12
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: , , USA.
Posts: 196
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to jmss66
Default insert or copy recordset from sql server to access database

I have two tables with the same field names. One is from SQL Server which I query and have a recordset from and want to insert or copy it into an access database.
How do it do this?

So far I have:
Code:
Do While Not rs_SQL_Element.EOF
rs_Element.AddNew
    Dim i As Integer, sFieldname As String
    For i = 1 To rs_Element.Fields.Count
       With rs_Element
       sFieldname = rs_SQL_Element.Fields.Item(i).Name
       If Not IsNull(rs_SQL_Element.Fields.Item(i).Value) Then
         sFieldname = rs_SQL_Element.Fields.Item(i).Value
        End If
        End With
 
    Next
 
    rs_Element.Update
    rs_SQL_Element.MoveNext
Loop
I can't seem to get the value of the fields from sql database to access.
Please help.
Thanks
Reply With Quote
  #2 (permalink)  
Old June 7th, 2011, 07:22 AM
Friend of Wrox
Points: 3,060, Level: 23
Points: 3,060, Level: 23 Points: 3,060, Level: 23 Points: 3,060, Level: 23
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2005
Location: , , .
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts
Default

Hi

The following code will be useful for inserting data to AccessDB (http://vbadud.blogspot.com/2009/02/blog-post_07.html)

However, since you are inserting records from another RDBMS, which definitely will be strucutred. Hence you can try using the Import feature of Access. Here you can map the columns, provide necessary criteria

Cheers
Shasur
__________________
C# Code Snippets (http://www.dotnetdud.blogspot.com)

VBA Tips & Tricks (http://www.vbadud.blogspot.com)
Reply With Quote
  #3 (permalink)  
Old June 7th, 2011, 08:26 AM
Friend of Wrox
Points: 1,035, Level: 12
Points: 1,035, Level: 12 Points: 1,035, Level: 12 Points: 1,035, Level: 12
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: , , USA.
Posts: 196
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to jmss66
Default

Hi Shasur, I was hoping to loop through field/column names instead of typing them one by one and assigning the value to them. Your example is making me type all of them. There are 350 fields in the table and the other table which I want to copy to has the exact corresponding fields or columns.

What I did in the VB application is select records from table A with various criteria and copy or populate table B with all the records in the result set. That's why I was hoping I can just find a code that basically says...table B = table A resultset.

Thanks,
Reply With Quote
  #4 (permalink)  
Old June 7th, 2011, 10:04 AM
Friend of Wrox
Points: 3,060, Level: 23
Points: 3,060, Level: 23 Points: 3,060, Level: 23 Points: 3,060, Level: 23
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2005
Location: , , .
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts
Default

Hi

I think the best option for you would be to import it

1) Export your record set as CSV
2) Import the CSV to Access

if needed you can manipuate the CSV in Excel

Regards
Shasur
__________________
C# Code Snippets (http://www.dotnetdud.blogspot.com)

VBA Tips & Tricks (http://www.vbadud.blogspot.com)
Reply With Quote
  #5 (permalink)  
Old June 7th, 2011, 10:22 AM
Friend of Wrox
Points: 1,035, Level: 12
Points: 1,035, Level: 12 Points: 1,035, Level: 12 Points: 1,035, Level: 12
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: , , USA.
Posts: 196
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to jmss66
Default

Hi Shasur,
I will go with that logic since no one seems to be able to give me a code or logic to be able to accomplish what I want to do iterating through field names.

Thanks,
jmss66
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to insert hindi text in sql server database through asp.net c# aniljks BOOK: Beginning ASP.NET 4 : in C# and VB 1 October 7th, 2010 02:29 AM
how to insert text file in sql server database sharvari_mothe Java Databases 3 June 5th, 2007 07:25 AM
copy a database using SQL Server 2000 samnachilomo SQL Server 2000 3 November 20th, 2006 01:15 AM
INSERT INTO from a SQL Server recordset? kcassidy Access 13 March 21st, 2006 08:35 AM



All times are GMT -4. The time now is 05:42 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.