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

Recommended Answers

All 7 Replies

Dim a , strsql as string 

'pls check your inputbox forget using it
'idont have any vb6 installed in my pc , now using csharp2005
a = InputBox("Input Product Code :", "Find", "")
If a = "" Then Exit Sub

'think this would help 

strsql = " select * from Product " 
strsql = strsql & " where " 
strsql = strsql & " pcode='" & trim(a) & "'"

Set rs = New ADODB.Recordset
rs.CursorLocation = AdUseClient

rs.open strsql, cn, AdOpenForwardonly, AdLockReadonly
'exit if no record 
if rs.Recordcount = 0 then exit sub
if rs.Recordcount > 0 Then 
          'display record in textbox
          'hope it helps 
          Text1.text = rs.Fields("pcode") 
          Text2.Text= rs.Fields("brandname") 
          etc....
          
         Set MSHFlexGrid1.DataSource = rs
end if
Command1.Enabled = False
Command2.Enabled = False
Command4.Enabled = False
Command5.Enabled = False

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 :(

bump

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'

yes i want to update what he edited from my database record. .

Right... So a select statement isn't meant for updating/editing... it's only meant for retrieval. You need the update sql query.

ok i try :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.