Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > Database and Reporting > update to sql server while going over the record's


Reply
 
Thread Tools Display Modes
  #1  
Old 10-01-2003, 04:16 AM
pelegk2 pelegk2 is offline
Junior Contributor
 
Join Date: Sep 2003
Posts: 233
Default update to sql server while going over the record's


i have made a select on a table
"select * from tblData"

and i want when i go over the fields that :
if rs("field1")="1" then
update field2=1 ' *
end if

how do i do (*)?
thnaks in advance
peleg
Reply With Quote
  #2  
Old 10-01-2003, 04:24 AM
rajeeshun rajeeshun is offline
Senior Contributor
 
Join Date: Oct 2002
Location: Dubai & Srilanka (Jaffna)
Posts: 1,151
Default

Quote:
Originally Posted by pelegk1
i have made a select on a table
"select * from tblData"

and i want when i go over the fields that :
if rs("field1")="1" then
update field2=1 ' *
end if

how do i do (*)?
thnaks in advance
peleg




What you want to do ???
Do you want to use wild cards in the update statement OR do you want to update a values as *
Reply With Quote
  #3  
Old 10-01-2003, 04:28 AM
pelegk2 pelegk2 is offline
Junior Contributor
 
Join Date: Sep 2003
Posts: 233
Default what i want to do

i am going over every line in the record set
i check 1 of the fields of that line
and in some condition if a feld called "field1" =1
then i want in the same line to update the value of field2 to 1!
and of course that this will be updates at the sql server
Reply With Quote
  #4  
Old 10-01-2003, 04:36 AM
rajeeshun rajeeshun is offline
Senior Contributor
 
Join Date: Oct 2002
Location: Dubai & Srilanka (Jaffna)
Posts: 1,151
Default

Quote:
Originally Posted by pelegk1
i am going over every line in the record set
i check 1 of the fields of that line
and in some condition if a feld called "field1" =1
then i want in the same line to update the value of field2 to 1!
and of course that this will be updates at the sql server




Then,
[VB]
if rs("field1")="1" then
update field2=1
End If
[/ VB]

is enough. Why are you using '*' ???
Reply With Quote
  #5  
Old 10-01-2003, 04:41 AM
pelegk2 pelegk2 is offline
Junior Contributor
 
Join Date: Sep 2003
Posts: 233
Default i use * beacuse i go over all the fields in

each row and read its values!


and no just to write "update field2=1" never will work!!"
Reply With Quote
  #6  
Old 10-01-2003, 04:46 AM
rajeeshun rajeeshun is offline
Senior Contributor
 
Join Date: Oct 2002
Location: Dubai & Srilanka (Jaffna)
Posts: 1,151
Default

Quote:
Originally Posted by pelegk1
each row and read its values!


and no just to write "update field2=1" never will work!!"




Put it into a Do while loop

Code:
Do while rs.EOF=False 'Put it your update code 'Instead of this, Why can't you use SQL commands. For Database operations (Insert. Update, Delete * Select) SQL is the only one best method and efficient method rs.MoveNext loop

Last edited by Shurik12; 02-14-2008 at 02:55 AM.
Reply With Quote
  #7  
Old 10-01-2003, 04:51 AM
pelegk2 pelegk2 is offline
Junior Contributor
 
Join Date: Sep 2003
Posts: 233
Default it is in a loop command tell me what to do next :

[this is in visual basic 6]

strSql = "select * from db1 where file1='0'"

Set rsecordSet = GetRecordSet(strSql)
While Not rsecordSet.EOF
field1= rsecordSet.Fields("field1")
x= rsecordSet.Fields("x")
y= rsecordSet.Fields("y")
z= rsecordSet.Fields("z")

rstA72RecordSet.Open "update A72 SET [FL00004] = 1 where (num=" & rstA72RecordSet.Fields("NUM") & ")"

rstA72RecordSet.MoveNext
Wend
Reply With Quote
  #8  
Old 10-01-2003, 04:56 AM
rajeeshun rajeeshun is offline
Senior Contributor
 
Join Date: Oct 2002
Location: Dubai & Srilanka (Jaffna)
Posts: 1,151
Default

Quote:
Originally Posted by pelegk1
[this is in visual basic 6]

strSql = "select * from db1 where file1='0'"

Set rsecordSet = GetRecordSet(strSql)
While Not rsecordSet.EOF
field1= rsecordSet.Fields("field1")
x= rsecordSet.Fields("x")
y= rsecordSet.Fields("y")
z= rsecordSet.Fields("z")

rstA72RecordSet.Open "update A72 SET [FL00004] = 1 where (num=" & rstA72RecordSet.Fields("NUM") & ")"

rstA72RecordSet.MoveNext
Wend




In your code ...
You are looping 'rsecordSet' recordset and doing move next for an another recordset 'rstA72RecordSet'
Reply With Quote
  #9  
Old 10-01-2003, 04:57 AM
pelegk2 pelegk2 is offline
Junior Contributor
 
Join Date: Sep 2003
Posts: 233
Default sory this is the correct doe :

strSql = "select * from db1 where file1='0'"

Set rsecordSet = GetRecordSet(strSql)
While Not rsecordSet.EOF
field1= rsecordSet.Fields("field1")
x= rsecordSet.Fields("x")
y= rsecordSet.Fields("y")
z= rsecordSet.Fields("z")

rsecordSet.Open "update A72 SET [FL00004] = 1 where (num=" & rstA72RecordSet.Fields("NUM") & ")"

rsecordSet.MoveNext
Wend


so whats next?
Reply With Quote
  #10  
Old 10-01-2003, 05:09 AM
rajeeshun rajeeshun is offline
Senior Contributor
 
Join Date: Oct 2002
Location: Dubai & Srilanka (Jaffna)
Posts: 1,151
Default

Quote:
Originally Posted by pelegk1
strSql = "select * from db1 where file1='0'"

Set rsecordSet = GetRecordSet(strSql)
While Not rsecordSet.EOF
field1= rsecordSet.Fields("field1")
x= rsecordSet.Fields("x")
y= rsecordSet.Fields("y")
z= rsecordSet.Fields("z")

rsecordSet.Open "update A72 SET [FL00004] = 1 where (num=" & rstA72RecordSet.Fields("NUM") & ")"

rsecordSet.MoveNext
Wend


so whats next?



Use connection.Execute to execute your SQL commands. You cannot do a execution by using Recordset.Open
Reply With Quote
  #11  
Old 10-01-2003, 05:49 AM
pelegk2 pelegk2 is offline
Junior Contributor
 
Join Date: Sep 2003
Posts: 233
Default thats what i wanted

thanks
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
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

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Update SQL Server database from vba code (SEEK or FIND) Ingineu Database and Reporting 2 09-08-2003 12:04 PM
SQL Server update using Inner Join? ebtsup Database and Reporting 0 04-29-2003 06:18 AM
Access & SQL server ferruh66 Database and Reporting 3 04-19-2003 03:15 PM
Creating Access Databases TomGuy Database and Reporting 8 07-10-2002 10:56 AM
Q's re. usage of SQL Server Mike Database and Reporting 6 07-02-2002 07:44 PM

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->