954,559 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

vb recordset problem

i was trying to join two tables using a adodb mysql5.1 driver connection .i tried to print the record count in the record set .
no result was shown and the program is not responding . when i started debugging it was shown that the record set object was closed .........pls help me................ my code is

Set myrs = New ADODB.Recordset
myrs.CursorLocation = adUseClient
myrs.CursorType = adOpenStatic
myrs.LockType = adLockReadOnly

myrs.Open " SELECT memberpersonal.name,memberpersonal.memberid, FROM memberpersonal,memberunion where(memberunion.memberid = memberpersonal.memberid and memberpersonal.memberid = '" & cmbUnion.Text & "')", mydatabase
MsgBox myrs.RecordCount
thanks in advance........

monurenjith
Newbie Poster
5 posts since May 2009
Reputation Points: 10
Solved Threads: 0
 

Hi, I just take a quick view to your code and I notice that your select statement have a " , " extra

SELECT memberpersonal.name,memberpersonal.memberid, FROM

I make it bold, Take it out.

regards.

jbisono
Posting Pro in Training
442 posts since May 2009
Reputation Points: 71
Solved Threads: 59
 

as suggested in the previous thread your sql statement is wrong.

debasisdas
Posting Genius
6,872 posts since Feb 2007
Reputation Points: 666
Solved Threads: 434
 

Should be something like...

myrs.Open " SELECT memberpersonal.name,memberpersonal.memberid, FROM memberpersonal, INNER JOIN memberunion ON memberpersonal.memberid = memberunion.memberid where memberunion.memberid = " & cmbUnion.Text , mydatabase


Good Luck

vb5prgrmr
Posting Virtuoso
1,912 posts since Mar 2009
Reputation Points: 156
Solved Threads: 296
 

Thanks......................

monurenjith
Newbie Poster
5 posts since May 2009
Reputation Points: 10
Solved Threads: 0
 

best way of practice in sql is that if you have a joined tables then use the keyword join (INNER JOIN, LEFT JOIN, RIGHT JOIN ETC...)

Dim sqlSelect As String

sqlSelect = " SELECT MP.name, MP.memberid "
sqlSelect = sqlSelect & "FROM MemberPersonal MP "
sqlSelect = sqlSelect & "INNER JOIN MembeRunion MR ON MP.memberid = MR.memberid "
sqlSelect = sqlSelect & "WHERE MR.memberid = " & cmbUnion.Text  

myrs.Open sqlSelect , mydatabase
jireh
Posting Whiz
316 posts since Jul 2007
Reputation Points: 11
Solved Threads: 49
 

'You have the wrong propereties for the recordset

With myrs
If .state = adStateOpen Then .Close
'
' set properties of recordset
.CursorType = adOpenDynamic
.CursorLocation = adUseClient
.LockType = adLockOptimistic

.Open sqlSelect , mydata
End With

Tassilo
Newbie Poster
2 posts since Jun 2009
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You