Editing a record!

Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jul 2008
Posts: 161
Reputation: ryan311 has a little shameless behaviour in the past 
Solved Threads: 1
ryan311 ryan311 is offline Offline
Junior Poster

Editing a record!

 
0
  #1
Dec 30th, 2008
help theres nothing happen everytime i search a record

heres my code

Dim a
a = InputBox("Input Product Code :", "Find", "")
If a = "" Then
Exit Sub
End If
Set rs = New ADODB.Recordset
rs.Open "Select * from Product where pcode='" & a & "'", cn, adOpenStatic, adLockPessimistic
Set MSHFlexGrid1.DataSource = rs
If rs.RecordCount > 0 Then
rs.Fields("pcode") = Text1.Text
rs.Fields("brandname") = Text2.Text
rs.Fields("genericname") = Text3.Text
rs.Fields("price") = Text4.Text
Command1.Enabled = False
Command2.Enabled = False
Command4.Enabled = False
Command5.Enabled = False
End If

nothing happen to my text fields
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 3
Reputation: Joel Salvo is an unknown quantity at this point 
Solved Threads: 1
Joel Salvo Joel Salvo is offline Offline
Newbie Poster

Re: Editing a record!

 
0
  #2
Dec 31st, 2008
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Dim a , strsql as string
  2.  
  3. 'pls check your inputbox forget using it
  4. 'idont have any vb6 installed in my pc , now using csharp2005
  5. a = InputBox("Input Product Code :", "Find", "")
  6. If a = "" Then Exit Sub
  7.  
  8. 'think this would help
  9.  
  10. strsql = " select * from Product "
  11. strsql = strsql & " where "
  12. strsql = strsql & " pcode='" & trim(a) & "'"
  13.  
  14. Set rs = New ADODB.Recordset
  15. rs.CursorLocation = AdUseClient
  16.  
  17. rs.open strsql, cn, AdOpenForwardonly, AdLockReadonly
  18. 'exit if no record
  19. if rs.Recordcount = 0 then exit sub
  20. if rs.Recordcount > 0 Then
  21. 'display record in textbox
  22. 'hope it helps
  23. Text1.text = rs.Fields("pcode")
  24. Text2.Text= rs.Fields("brandname")
  25. etc....
  26.  
  27. Set MSHFlexGrid1.DataSource = rs
  28. end if
  29. Command1.Enabled = False
  30. Command2.Enabled = False
  31. Command4.Enabled = False
  32. Command5.Enabled = False
Last edited by Ancient Dragon; Jan 5th, 2009 at 3:17 pm. Reason: add code tags
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 161
Reputation: ryan311 has a little shameless behaviour in the past 
Solved Threads: 1
ryan311 ryan311 is offline Offline
Junior Poster

Re: Editing a record!

 
0
  #3
Jan 1st, 2009
thanks its work but i have problem in saving a data

Set rs = New ADODB.Recordset
rs.Open "Select * from Product", cn, adOpenKeyset, adLockPessimistic
If Not rs.EOF Then
rs.Fields("pcode").Value = Text1.Text
rs.Fields("brandname").Value = Text2.Text
rs.Fields("genericname").Value = Text3.Text
rs.Fields("price").Value = Text4.Text
rs.Update
End If

i hope you can help me
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 161
Reputation: ryan311 has a little shameless behaviour in the past 
Solved Threads: 1
ryan311 ryan311 is offline Offline
Junior Poster

Re: Editing a record!

 
0
  #4
Jan 2nd, 2009
bump
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: Editing a record!

 
0
  #5
Jan 2nd, 2009
I'm a little confused.... you are trying to save data? If so, you wouldn't open a connection to the database with a Select... Select is used to retrieve rows and columns from the database table.... I think you want something like with like
UPDATE table SET field = 'whatever' WHERE column = 'something'
Last edited by Comatose; Jan 2nd, 2009 at 11:16 am.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 161
Reputation: ryan311 has a little shameless behaviour in the past 
Solved Threads: 1
ryan311 ryan311 is offline Offline
Junior Poster

Re: Editing a record!

 
0
  #6
Jan 2nd, 2009
yes i want to update what he edited from my database record. .
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: Editing a record!

 
0
  #7
Jan 2nd, 2009
Right... So a select statement isn't meant for updating/editing... it's only meant for retrieval. You need the update sql query.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 161
Reputation: ryan311 has a little shameless behaviour in the past 
Solved Threads: 1
ryan311 ryan311 is offline Offline
Junior Poster

Re: Editing a record!

 
0
  #8
Jan 2nd, 2009
ok i try
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for Visual Basic 4 / 5 / 6
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC