PDA

View Full Version : Select , Count(*) in MySQL


kafsar
01-29-2005, 11:45 AM
I write the following code in vb6 its work fine for Access and MSSQL but not work with MySQL, RecordCount return -1 always kindly help me..


Dim mms As ADODB.Connection

Set mms = New ADODB.Connection
mms.ConnectionString = "DRIVER = MYSQL ODBC 3.51 Driver;SERVER=10.48.60.183;DATABASE=mms;UID=kma;pwd=abcd
mms.Open

Set rstIWOrder = New ADODB.Recordset

SelectString = "select * from IWOrder where WON ='"
SelectString = SelectString + txtIWO.Text + "'"
rstIWOrder.Open SelectString, mms, adOpenStatic, adLockReadOnly

If rstIWOrder.RecordCount = 0 Then
MsgBox "Internal Work Order not Found in Database"

else

or

SelectString = "select count(*) from IWOrder where WON ='"
SelectString = SelectString + txtIWO.Text + "'"
rstIWOrder.Open SelectString, mms, adOpenStatic, adLockReadOnly

raf
01-29-2005, 01:06 PM
welcome here!

RecordCount is a recordset-function so it has nothing to do with sql or the db-format.
the reason why you get a -1 value is because of your cursortype.

just use the

SELECT COUNT(*) as reccount FROM ...

and then get the value with
rstIWOrder.Fields("reccount").Value