Skip to content
Advertisement

VB.NET SQL statement doesn’t return any rows form Access database

I have the following code for a login winform. When I make the connection to the database and make a select statement I get no rows back. I’m getting the message “No data exists for the row/column.”

But there are rows and columns in the database.

Can someone tell me what I do wrong?

Advertisement

Answer

The problem was checking dr.Item() before ever calling dr.Read(). Aside from the that, make sure the username in UsernameTextBox actually exists in the database, fix those nasty plain-text passwords, and you’ll be fine.

One final concern. I’m not sure which OLE provider you’re using, but last time I checked most providers where it makes sense to use OLE want you to use ? placeholders instead of named parameters. So the SQL command would look like this:

But if you’re really using MySql, as the connection string name suggests, you really do so much better getting the real MySql ADO.Net library instead of OleDB: minor performance gain, better error messaging, etc.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement