943,840 Members | Top Members by Rank

Ad:
Dec 30th, 2008
0

Editing a record!

Expand Post »
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
Similar Threads
Reputation Points: 3
Solved Threads: 5
Posting Whiz in Training
ryan311 is offline Offline
254 posts
since Jul 2008
Dec 31st, 2008
0

Re: Editing a record!

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
Reputation Points: 10
Solved Threads: 1
Newbie Poster
Joel Salvo is offline Offline
3 posts
since Mar 2008
Jan 1st, 2009
0

Re: Editing a record!

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
Reputation Points: 3
Solved Threads: 5
Posting Whiz in Training
ryan311 is offline Offline
254 posts
since Jul 2008
Jan 2nd, 2009
0

Re: Editing a record!

bump
Reputation Points: 3
Solved Threads: 5
Posting Whiz in Training
ryan311 is offline Offline
254 posts
since Jul 2008
Jan 2nd, 2009
0

Re: Editing a record!

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.
Team Colleague
Reputation Points: 361
Solved Threads: 214
Taboo Programmer
Comatose is offline Offline
2,413 posts
since Dec 2004
Jan 2nd, 2009
0

Re: Editing a record!

yes i want to update what he edited from my database record. .
Reputation Points: 3
Solved Threads: 5
Posting Whiz in Training
ryan311 is offline Offline
254 posts
since Jul 2008
Jan 2nd, 2009
0

Re: Editing a record!

Right... So a select statement isn't meant for updating/editing... it's only meant for retrieval. You need the update sql query.
Team Colleague
Reputation Points: 361
Solved Threads: 214
Taboo Programmer
Comatose is offline Offline
2,413 posts
since Dec 2004
Jan 2nd, 2009
0

Re: Editing a record!

ok i try
Reputation Points: 3
Solved Threads: 5
Posting Whiz in Training
ryan311 is offline Offline
254 posts
since Jul 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: changing the backcolor
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: Audio volume control on vb6 form





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC