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

Adodc1.Recordset!name = text1.text

Hi,

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

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

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

Regards
Veena

Hi,

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

adodc1.recordsource = "Select name from emp where name='" & Text2.Text & "'"
Adodc1.Refresh
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)

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)

that is your "first field" which is "name" no need to type the name.

have you try this one? Adodc1.Recordset!name = text1.text

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

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

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

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.