Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
  #1  
Old July 5th, 2004, 02:42 AM
session session is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 5 session User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thumbs down i m looking for someone who can solve my vb problem quickly????????

hi

i want to save the records from two tables into third table.now the problem is that when i click the save button in third table then first record of first table is saved twice with first and second record of second table.the code is shown below



Public rs As New ADODB.Recordset
Public rs1 As New ADODB.Recordset
Public rs2 As New ADODB.Recordset
Public cn As New ADODB.Connection
Public STR As String
Public a As String
Dim t As String
Dim d As Date
Private Sub cmdsave_Click()
Command1.Enabled = True
If rs2.State = adStateOpen Then rs2.Close
rs2.Open "select * from table2", cn, adOpenKeyset, adLockOptimistic
rs2.AddNew
rs2!trouble_ticket_no = txtno.Text
rs2!fault_time = txtfault.Text
MsgBox ("entries have been saved")
rs2.Update
If rs1.State = adStateOpen Then rs1.Close
rs1.Open "select * from table1", cn, adOpenKeyset, adLockOptimistic
If rs2.State = adStateOpen Then rs2.Close
rs2.Open "select * from table2", cn, adOpenKeyset, adLockOptimistic
If rs.State = adStateOpen Then rs.Close
rs.Open "select * from table3", cn, adOpenKeyset, adLockOptimistic
If rs1.BOF = True And rs2.BOF = True Then
rs!Date1 = rs1!Date1
rs!customer_name = rs1!customer_name
rs!reported_to = rs1!reported_to
rs!reported_by = rs1!reported_by
rs!description_of_fault = rs1!description_of_fault
rs!trouble_ticket_no = rs2!trouble_ticket_noH
rs!fault_time = rs2!fault_time
rs!Update = rs2!Update
rs2.MoveNext
rs1.MoveNext
rs.Update
Else
rs2.MoveLast
rs1.MoveLast
rs.AddNew
rs!Date1 = rs1!Date1
rs!customer_name = rs1!customer_name
rs!reported_to = rs1!reported_to
rs!reported_by = rs1!reported_by
rs!description_of_fault = rs1!description_of_fault
rs!trouble_ticket_no = rs2!trouble_ticket_no
rs!fault_time = rs2!fault_time
rs!Update = rs2!Update
rs.Update
End If
End Sub

Reply With Quote
  #2  
Old July 5th, 2004, 03:12 AM
zwonimir zwonimir is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: May 2004
Location: East Side Verona, Southern Europe
Posts: 98 zwonimir User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
try this (I think) if the tables has 3 fields (FieldNum, FieldTxt and FieldTxt2):

Quote:
dim rs1 as adodb.recordset, cmd as adodb.command

set rs1=new adodb.recordset
rs1.open "SELECT * FROM Table1", conn, 1
while not rs1.eof
set cmd=new adodb.command
cmd.commandtext="INSERT INTO Table3 (FieldNum, FieldTxt, FieldTxt2) VALUES ("+rs1.fields(0).value+", '"+rs1.fields(1).values+"', '"+rs1.fields(2).values+"')"
cmd.ActiveConnection = conn
cmd.Execute
set cmd = Nothing
rs1.movenext
wend
rs1.close
set rs1 = Nothing
set rs1=new adodb.recordset
rs1.open "SELECT * FROM Table2", conn, 1
while not rs1.eof
set cmd=new adodb.command
cmd.commandtext="INSERT INTO Table3 (FieldNum, FieldTxt, FieldTxt2) VALUES ("+rs1.fields(0).value+", '"+rs1.fields(1).values+"', '"+rs1.fields(2).values+"')"
cmd.ActiveConnection = conn
cmd.Execute
set cmd = Nothing
rs1.movenext
wend
rs1.close
set rs1 = Nothing

... or ...

Quote:
dim rs1 as adodb.recordset, cmd as adodb.command

set rs1=new adodb.recordset
rs1.open "SELECT * FROM Table1,Table2", conn, 1
while not rs1.eof
set cmd=new adodb.command
cmd.commandtext="INSERT INTO Table3 (FieldNum, FieldTxt, FieldTxt2) VALUES ("+rs1.fields(0).value+", '"+rs1.fields(1).values+"', '"+rs1.fields(2).values+"')"
cmd.ActiveConnection = conn
cmd.Execute
set cmd = Nothing
rs1.movenext
wend
rs1.close
set rs1 = Nothing


Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingVisual Basic Programming > i m looking for someone who can solve my vb problem quickly????????


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 

Iron Speed




© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway