Reply

Join Date: Sep 2007
Posts: 70
Reputation: kehar is an unknown quantity at this point 
Solved Threads: 0
kehar kehar is offline Offline
Junior Poster in Training

ADODC syntax

 
0
  #1
Apr 12th, 2009
Hi everbody,
I have used one ADODC control in my VB6 prog with SQL 2000 as backend. I have completed the connection of ADODC using UDL file and it's working fine
But when i write the following syntax to retrieve data its not working: The code is as under:

Private sub cmdview_click()
adodc1.recordsource = "Select name from emp where name=Arun"
text1.text =adodc1.recordset
endsub
I tried this code also:
adodc1.recordset ="Select name from emp where name= ' " & text2.text & "' "
But this also did not work.
whereas cmdadd is working fine where the code is written as under :
adodc1.recordset. Addnew
Adodc1.recordset!name =text3.text
Pl help me early.

(Kehar Singh)



T
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 164
Reputation: rm_daniweb is an unknown quantity at this point 
Solved Threads: 10
rm_daniweb rm_daniweb is offline Offline
Junior Poster

Re: ADODC syntax

 
0
  #2
Apr 13th, 2009
Adodc1.Recordset!name = text1.text
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 848
Reputation: QVeen72 is on a distinguished road 
Solved Threads: 120
QVeen72's Avatar
QVeen72 QVeen72 is offline Offline
Practically a Posting Shark

Re: ADODC syntax

 
0
  #3
Apr 13th, 2009
Hi,

Immediately after setting recordsource, you have to refresh..
try this :

  1. adodc1.recordsource = "Select name from emp where name='" & Text2.Text & "'"
  2. Adodc1.Refresh
  3. text1.text =adodc1.recordset.Fields(0)

Also check, ConnectionString is set before running the above code..

Regards
Veena
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 70
Reputation: kehar is an unknown quantity at this point 
Solved Threads: 0
kehar kehar is offline Offline
Junior Poster in Training

Re: ADODC syntax

 
0
  #4
Apr 13th, 2009
Originally Posted by QVeen72 View Post
Hi,

Immediately after setting recordsource, you have to refresh..
try this :

  1. adodc1.recordsource = "Select name from emp where name='" & Text2.Text & "'"
  2. Adodc1.Refresh
  3. text1.text =adodc1.recordset.Fields(0)

Also check, ConnectionString is set before running the above code..

Regards
Veena
Hi
Although I have written the connection string in Form load view.
and even the ADODC has been connected to the database using DSN in its property window.
Earlier when I did not use ADODC control in form that time I used to write the following code in General declaration view of Code
Dim cn as new ADODB.Connection
Dim rs as new ADODB.recordset
Should I write the above code even after using ADODC control in General declaration ?

(kehar singh)
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 70
Reputation: kehar is an unknown quantity at this point 
Solved Threads: 0
kehar kehar is offline Offline
Junior Poster in Training

Re: ADODC syntax

 
0
  #5
Apr 13th, 2009
adodc1.recordsource = "Select name from emp where name='" & Text2.Text & "'"
Adodc1.Refresh
text1.text =adodc1.recordset.Fields(0)

What does Fields(0) stand for in above code ? Does it mean I should write the field name or column of the field where name exist.
Pl make it clear.

(Kehar Singh)
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 164
Reputation: rm_daniweb is an unknown quantity at this point 
Solved Threads: 10
rm_daniweb rm_daniweb is offline Offline
Junior Poster

Re: ADODC syntax

 
0
  #6
Apr 13th, 2009
that is your "first field" which is "name" no need to type the name.

have you try this one? Adodc1.Recordset!name = text1.text
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 70
Reputation: kehar is an unknown quantity at this point 
Solved Threads: 0
kehar kehar is offline Offline
Junior Poster in Training

Re: ADODC syntax

 
0
  #7
Apr 13th, 2009
Originally Posted by rm_daniweb View Post
that is your "first field" which is "name" no need to type the name.

have you try this one? Adodc1.Recordset!name = text1.text
My entire code is as under :

Dim cn As New ADODB.Connection ' in General declaration


Private Sub cmdaddnew_Click() ' This is working fine
Adodc1.Recordset.AddNew
Adodc1.Recordset!ono = Text6.Text
Adodc1.Recordset!ord = Text7.Text
Adodc1.Recordset!pop = Text8.Text
End Sub

Private Sub cmddelete_Click() ' Not working
Adodc1.Recorsource = "Select * from aot where ono='" & Text9.Text & "'"
If Adodc1.Recordset.EOF Then
MsgBox "Record not found"
Exit Sub
Else
Adodc1.Recordset.Delete
End If
End Sub


Private Sub cmdview_Click() ' Not working
Adodc1.RecordSource = "Select ord from aot for pop='" & Text9.Text & "'"
Text3.Text = Adodc1.Recordset.fields(1)
End Sub

Private Sub Form_Load() 'its Ok
cn.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=ao"
cn.Open
End Sub

command under cmdview and cmd delete are not working
Pl help me

Kehar singh
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 164
Reputation: rm_daniweb is an unknown quantity at this point 
Solved Threads: 10
rm_daniweb rm_daniweb is offline Offline
Junior Poster

Re: ADODC syntax

 
0
  #8
Apr 14th, 2009
Dim YourTextbox as string
Use YourTextbox in query
instead of the Object;

another is use trim() may be you have some spaces.

after query use refresh
Adodc1.Refresh

Wrong spelling on Recordsource: Adodc1.Recorsource = "Select * from aot where ono='" & Text9.Text & "'"

In delete.
Adodc1.Recordset.Delete adAffectCurrent
Last edited by rm_daniweb; Apr 14th, 2009 at 1:05 am.
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 848
Reputation: QVeen72 is on a distinguished road 
Solved Threads: 120
QVeen72's Avatar
QVeen72 QVeen72 is offline Offline
Practically a Posting Shark

Re: ADODC syntax

 
0
  #9
Apr 15th, 2009
Hi,

Whenever you change Recordset for ADODC control, Immediately follow this Code : ADODC1.Refresh

No, where in your code, you have written that. I have already Mentioned this in my first post...

Regards
Veena
Reply With Quote Quick reply to this message  
Reply

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



Similar Threads
Other Threads in the Visual Basic 4 / 5 / 6 Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC