[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.vb.general.discussion

OleDB Select Top statement not returning data??

Locke Nash Cole

7/13/2010 8:28:00 AM

The while reader.read returns no data at all (msgbox doesnâ??t even fire),
there should be one row returned. When I execute this exact statement
against the same access database within Microsoft Access I get my one row.
Any ideas?

MsgBox("building sql")
Dim SQLcmd As String = String.Format("SELECT TOP 1
Suspects.Moniker FROM Suspects WHERE (((Suspects.Moniker) Like 'Unknown.*'))
ORDER BY Suspects.Moniker DESC")
Dim sVersion As String = vbNullString
Dim SQLExec As New OleDbCommand

SQLExec.Connection = SpyBareDB
SQLExec.CommandText = SQLcmd

Dim reader As OleDbDataReader = SQLExec.ExecuteReader()
While reader.Read()
MsgBox("getting string")
MsgBox(reader.GetString(0))
End While

3 Answers

(nobody)

7/13/2010 3:17:00 PM

0

"Joseph N. Stackhouse" <junkmauler@hotmail.com> wrote in message
news:uqMjFVmILHA.4400@TK2MSFTNGP05.phx.gbl...
> Dim SQLcmd As String = String.Format("SELECT TOP 1

This group is for VB6 and earlier(VB Classic). For VB.Net, you need to use
the online forums provided by Microsoft or others, as they have shut down
the dotnet newsgroups about a week ago.


Paul Clement

7/13/2010 7:24:00 PM

0


On Tue, 13 Jul 2010 04:27:37 -0400, "Joseph N. Stackhouse" <junkmauler@hotmail.com> wrote:

¤ The while reader.read returns no data at all (msgbox doesn?t even fire),
¤ there should be one row returned. When I execute this exact statement
¤ against the same access database within Microsoft Access I get my one row.
¤ Any ideas?
¤
¤ MsgBox("building sql")
¤ Dim SQLcmd As String = String.Format("SELECT TOP 1
¤ Suspects.Moniker FROM Suspects WHERE (((Suspects.Moniker) Like 'Unknown.*'))
¤ ORDER BY Suspects.Moniker DESC")
¤ Dim sVersion As String = vbNullString
¤ Dim SQLExec As New OleDbCommand
¤
¤ SQLExec.Connection = SpyBareDB
¤ SQLExec.CommandText = SQLcmd
¤
¤ Dim reader As OleDbDataReader = SQLExec.ExecuteReader()
¤ While reader.Read()
¤ MsgBox("getting string")
¤ MsgBox(reader.GetString(0))
¤ End While

Probably more of a SQL question. The wild-card character for ADO/OLEDB is a percent sign character
and not an asterisk (as when running the query from Microsoft Access).

If you need to run this query from Access as well then use the undocumented ALIKE keyword with the
percent sign as the wild-card character.


Paul
~~~~
Microsoft MVP (Visual Basic)

Locke Nash Cole

7/14/2010 9:22:00 AM

0

Paul thank you very much I racked my brain for a few hours on this one!
Damn you asterisks! ;)


"Paul Clement" wrote in message
news:e1fp36h6cpn64n1vr23j9v6eekj81n63vi@4ax.com...

On Tue, 13 Jul 2010 04:27:37 -0400, "Joseph N. Stackhouse"
<junkmauler@hotmail.com> wrote:

¤ The while reader.read returns no data at all (msgbox doesnâ??t even fire),
¤ there should be one row returned. When I execute this exact statement
¤ against the same access database within Microsoft Access I get my one row.
¤ Any ideas?
¤
¤ MsgBox("building sql")
¤ Dim SQLcmd As String = String.Format("SELECT TOP 1
¤ Suspects.Moniker FROM Suspects WHERE (((Suspects.Moniker) Like
'Unknown.*'))
¤ ORDER BY Suspects.Moniker DESC")
¤ Dim sVersion As String = vbNullString
¤ Dim SQLExec As New OleDbCommand
¤
¤ SQLExec.Connection = SpyBareDB
¤ SQLExec.CommandText = SQLcmd
¤
¤ Dim reader As OleDbDataReader = SQLExec.ExecuteReader()
¤ While reader.Read()
¤ MsgBox("getting string")
¤ MsgBox(reader.GetString(0))
¤ End While

Probably more of a SQL question. The wild-card character for ADO/OLEDB is a
percent sign character
and not an asterisk (as when running the query from Microsoft Access).

If you need to run this query from Access as well then use the undocumented
ALIKE keyword with the
percent sign as the wild-card character.


Paul
~~~~
Microsoft MVP (Visual Basic)