I want to show record list in Datacombo through coding , using SQL Server 2000,VB6.

Following are the coding.

********************************
Private Sub Form_Load()

Dim CNN As New ADODB.Connection
Dim RST As New ADODB.Recordset

Set CNN = New ADODB.Connection
CNN.Provider = "SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=Maintenance;Data Source=YASIR"
CNN.Open

Set RST = New ADODB.Recordset

RST.Open "SELECT * FROM MAINT", CNN, adOpenKeyset, adLockOptimistic

Set DataCombo1.RowSource = RST
DataCombo1.ListField = Mill
Text1 = RST!Mill

End Sub

********************************
Text1(textbox) is showing record it means dataconnection is established. but no record showing in Datacombo. Please help .one thing more that if I use Ms Access Database then record is showing Datacombo,(just chaning on cnn.provider....)

Thanks
Yasir Farid

Recommended Answers

All 9 Replies

Please check up whether after placing the period(dot) after DataCombo1 the methods RowSourse and ListFields are poping up.
If they are, please get back to me.

Yor connection strings are having some problem that I will tell you.

Hi Yasir,

Check This :

Set DataCombo1.RowSource = RST DataCombo1.ListField= "Mill"

Wrap Mill with double Quotes ( " )

Regards
Veena

Please check up whether after placing the period(dot) after DataCombo1 the methods RowSourse and ListFields are poping up.
If they are, please get back to me.

Yor connection strings are having some problem that I will tell you.

yes after placing the period (dof) Rowsource and Listfields are popping up.

Veena
Yes I have done, but still not working...

Yasir

Hi Yasir,

Check This :

Set DataCombo1.RowSource = RST DataCombo1.ListField= "Mill"

Wrap Mill with double Quotes ( " )

Regards
Veena

Hi Yasir,
Open Recordset this way :

Set RST = New ADODB.Recordset
RST.CursorLocation = adUseClient
RST.Open "SELECT * FROM MAINT", CNN, adOpenKeyset, adLockOptimistic


After filling, it dosent show on the Combo's Text, To Check Click on then DropDown Arrow of the Combo, It will be filled,

REgards
Veena

Hi,

If still that did not work then
Open recordset this way :(Static / Read Only)


RST.Open "SELECT * FROM MAINT", CNN, adOpenStatic, adLockReadOnly

Regards
Veena

I want to show record list in Datacombo through coding , using SQL Server 2000,VB6.

Following are the coding.

********************************
Private Sub Form_Load()

Dim CNN As New ADODB.Connection
Dim RST As New ADODB.Recordset

Set CNN = New ADODB.Connection

'Please avoid the above underlined One

CNN.Provider = "SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=Maintenance;Data Source=YASIR"

'Change all those underlined above as below

CNN.ConnectionString="Provider=SQLOLEDB.1;UID=sa;PWD=sa;Data Sourse=YASIR;Initial Catalog=Maintenance"

'If the UserID & Password are not 'sa' please change it accordingly.

CNN.Open

Set RST = New ADODB.Recordset

'Instead of above line please give as below

RST.ActiveConnection = CNN

If RST.State = adStateOpen then
RST.Close
End If

RST.Open "SELECT * FROM MAINT", CNN, adOpenKeyset, adLockOptimistic

'See that the table above underlined exist in the database Maintenance.

Set DataCombo1.RowSource = RST
DataCombo1.ListField = Mill
Text1 = RST!Mill

If RST.State = adStateOpen then
RST.Close
End If

End Sub

********************************
Text1(textbox) is showing record it means dataconnection is established. but no record showing in Datacombo. Please help .one thing more that if I use Ms Access Database then record is showing Datacombo,(just chaning on cnn.provider....)

Thanks
Yasir Farid

Yasir, I have underlined the code that you have to change or replace
then run it and get back to me.

AV Manoharan

Yes Veena Thank you,

After applying RST.CursorLocation = adUseClient, its shows records on datacombo..Thanks again.

meet you soon with other trouble.;)

Yasir

Veena, you your aptitude is to be appreciated, even i had the same problem. from access, data coming in db combo, but not from sql...how can we guess, there is something wrong in the code, (in the way, data is picked up from sql...)

thanks a lot...

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.