ADO Recordset returns nothing

Asked

Viewed 230 times

0

I can’t get ADO Recordset to return records from a Mysql table. I’m using VB.NET in Visual Studio. I can establish the communication with the database, make the connection, create tables, all via connection object (as below) but when returning the information via Recordset, gives error.

Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim fld As ADODB.Field
Dim aux As String

aux = "Provider = MSDASQL;Driver={MySQL ODBC 5.2 ANSI Driver}; Server=localhost; Database = db-teste; User=root; Password=123456; Option=3;"
conn.Open(aux)

'create table
conn.Execute("DROP TABLE IF EXISTS my_ado")
conn.Execute("CREATE TABLE my_ado(id int Not null primary key, name varchar(20)," &
                "txt text, dt date, tm time, ts timestamp)")
'insert
conn.Execute("INSERT INTO my_ado(id,name,txt) values(1,100,'venu')")
conn.Execute("INSERT INTO my_ado(id,name,txt) values(2,200,'MySQL')")

'============================================================================
' ATÉ AQUI VINHA FUNCIONANDO OK!
'============================================================================


' Isso não retorna nada
rs.Open("SELECT * FROM my_ado", conn)
rs.MoveFirst()

' RecordCount retorna sempre "-1" <<<<<<====================
Debug.Print(Str(rs.RecordCount()))

' rs.Fields já vem com erro
For Each fld In rs.Fields 
    Debug.Print(fld.Name)
Next

What is wrong?

  • dude, have you checked if this sql returns anything directly in the database? SELECT * FROM my_ado Checked whether the connection that is apsing in rs.Open("SELECT * FROM my_ado", conn) really is pointing to the right place ?

  • whether this is Vb.net pq uses recordset? it is not possible to use something like datareader? https://msdn.microsoft.com/pt-br/library/haa3afyz(v=vs.110).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-2

  • Hello @Meajudasilvio. Yes, I checked directly in the database if the table is created (it is created and the records are there too). Up to the point where I put the comment "UP HERE WAS WORKING OK!" the code is perfect. After this point of the comment the thing ceases to make sense. I’m using VB in Visual Studio 2017. Yes, I can do with "datareader" without problems, but in this specific case I need to do with ADODB, because I can not accept the lack of solution of this problem, even if it was just out of curiosity.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.