473,386 Members | 1,835 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

How to insert datas from one table to another using ADO connection

Hello

I am using windows XP

I need a small programme in Visual basic 6 with Access 2000

I have two tables for example one table named student other table named section

In student table rno is primary key. In section table Rollno is primary key


Both tables have datas, I want to insert datas(multiple rows) from student to section.

The coditions is unique datas only (ie. some datas already in section while inserting
datas from student to section the existing datas should be eliminated they wont be inserted)
( by comparin rno with rollno)( i avoid duplicate appending)

Please me code for inserting tables using ADODB recordset




A.Senthil kumar
Sep 10 '08 #1
3 6733
PianoMan64
374 Expert 256MB
Hello

I am using windows XP

I need a small programme in Visual basic 6 with Access 2000

I have two tables for example one table named student other table named section

In student table rno is primary key. In section table Rollno is primary key


Both tables have datas, I want to insert datas(multiple rows) from student to section.

The coditions is unique datas only (ie. some datas already in section while inserting
datas from student to section the existing datas should be eliminated they wont be inserted)
( by comparin rno with rollno)( i avoid duplicate appending)

Please me code for inserting tables using ADODB recordset




A.Senthil kumar

Hey A.Senthil kumar,

The first issue that you're going to have to get around is that the RNO and RollNo CAN NOT be used as a method to compare if an item has been added to the table or not. The reason is, if for some reason that the numbers get out of sync, then you don't have any way of locating that particular record.

You would be better off to have another field as the primary key and store RNO number into the Section table.

That way if you want to do a lookup and find out if that item has been added to the section table, then you would be able to locate them.

In order to copy a records from one table to another, the ADO code for that is as follow:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Dim cn As ADODB.Connection
  3. Dim cmd As ADODB.Command
  4.  
  5.  
  6. Sub MoveRecords()
  7.     Set cn = New ADODB.Connection
  8.     With cn
  9.             .Provider = "Microsoft.Jet.OLEDB.4.0" ' OLEDB file that is required to connect to MS Access 2003 or less.
  10.             .Properties("Data Source").Value = "E:\My Documents\db7.mdb" 'Full Path to Data Source
  11.             .Properties("Persist Security Info").Value = False
  12.             .Open
  13.     End With
  14.  
  15.     Set cmd = New ADODB.Command
  16.     With cmd
  17.             Set .ActiveConnection = cn
  18.             .CommandText = "INSERT INTO [Section] ( RNO, StudentName )" & _
  19.                            "SELECT Student.Rno, Student.StudentName " & _
  20.                            "FROM Student LEFT JOIN [Section] ON Student.Rno = Section.RNO " & _
  21.                            "WHERE (((Section.RollNo) Is Null));"
  22.             .CommandType = adCmdText
  23.             .Execute
  24.     End With
  25. End Sub
  26.  
Hope this gives you some kind of clue as to what you need to do.

Joe P.

p.s. I've included the sample data file that works with the code that I've provided. just change the path to the location of your my documents folder and you'll be able to see what I mean.
Attached Files
File Type: zip db7.zip (9.4 KB, 349 views)
Nov 17 '08 #2
NeoPa
32,556 Expert Mod 16PB
As a general rule, we don't simply provide code upon request. Particularly when someone asks for it without indicating what, if anything, they have attempted so far.

Having said that, some sample (illustrative) DAO code can be found at Basic DAO recordset loop using two recordsets. You will need to extract the concept and do the main work yourself of course, but this gives a good starting point.

Welcome to Bytes!
Nov 17 '08 #3
missinglinq
3,532 Expert 2GB
This thread deals with a Visual Basic front end, and as such, needs to be addressed in that forum. Since a duplicate thread has already been posted there, I'm simply going to close this thread.

In the future, please do not post multiple copies a thread.

From FAQs

Do Not Double Post Your Questions

Double posting is where you start a thread on a topic and then for some reason start another thread on exactly the same topic in the same forum or in another forum on the same site. Please do not do this because

1. It makes it very hard for people to answer you especially if there are answers happening in all the threads you have started because they have to read 2 or more threads in order to see what has already been said.
2. It swamps the forum with your problem resulting in less attention for the other threads.

Look over your question, using some native intelligence, and decide which forum your tread belongs in.

Thank you for your attention in this matter.

Welcome to Bytes!

Linq ;0)>
Nov 17 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: shank | last post by:
I have a recordset that contains multiple records of product a user is purchasing. For clarity, I converted the recordset fields to variables. I need to take that entire recordset and insert it...
4
by: brent.ryan | last post by:
How do I get the next int value for a column before I do an insert in MY SQL Server 2000? I'm currently using Oracle sequence and doing something like: select seq.nextval from dual; Then I...
5
by: Fabrice | last post by:
Hello everybody, I'm working with Access 2002. I have to import Data from a Foxpro table that contains 25000 records in an Access table. I have a couple of restrictions placed on me for the...
2
by: Eli | last post by:
Hi all We currently have a strange problem with calling a Stored Procedure (SQL Database) in our C# Project. The only error I get is "System error" which says a lot :) Background: We have...
9
by: David Eades | last post by:
Hi all Complete newbie here, so apologies if this is the wrong forum. I've been asked to use mysql and asp to make a simple bidding system (rather like a simple ebay), whereby users can use a...
3
by: nolanmadson | last post by:
I'm creating a front-end for some Teradata user maintenance tables in MS Access. I've started having problems in occasionally not being able to insert or update records in these tables. I've been...
6
by: kavithadevan | last post by:
Hi, I am trying to retriving some datas from the database.using submit button i am getting result but i inserted one submit image and i gave link to that image and then i run that script but its...
6
by: Abandoned | last post by:
Hi.. I use the threading module for the fast operation. But i have some problems.. This is my code sample: ================= conn =...
0
by: imagetvr | last post by:
Hello I am using windows XP I need a small programme in Visual basic 6 with Access 2000 I have two tables for example one table named student other table named section In student table...
4
by: AXRabbit | last post by:
Hi, i am now doing a Car rental system web project. Well the interface is very similiar to http://www.avis.com.sg/, which i have extra modelname dropdownlist. Here is my code.Label 7 is just a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.