Go Back  Xtreme Visual Basic Talk > Visual Basic .NET (2002/2003/2005/2008, including Express editions) > .NET Database and Reporting > No data exists for row/column


Reply
 
Thread Tools Display Modes
  #1  
Old 07-30-2012, 09:21 AM
HappyJoni's Avatar
HappyJoni HappyJoni is offline
Centurion
 
Join Date: Jun 2003
Location: New Jersey
Posts: 150
Question No data exists for row/column


I'm trying to access a foxpro database and perform the following query in vb.net:

SELECT market, COUNT(cati_id) as idcnt FROM floridaaddress112 GROUP BY market

I'm getting an error that says "Error: no data exists for row/column".
I'm not sure what I'm doing wrong. When I open the database in Foxpro and run the same query it works fine.

Can anyone see where I'm going wrong?? (see code below)



Module Module1

Public Sub databaseTest1()
Dim InputFileName As String
Dim RecordsExported As Long = 0, RowNumber As Long = 0
Dim Conn As New OleDb.OleDbConnection
Dim Cmd As New OleDb.OleDbCommand
Dim Adapt As New OleDb.OleDbDataAdapter
Dim Read As OleDb.OleDbDataReader
Dim Msg As String

Msg = "Error : "
InputFileName = "c:\dev\vendorbuilderpro\vendorbuilderpro\tables\floridaaddress112.dbf "

Try
Conn.ConnectionString = "Provider=VFPOLEDB.1;Data Source=" & _
InputFileName & ";Mode=Read|Share Deny None;Collating Sequence=MACHINE"

Conn.Open()
Cmd.CommandType = CommandType.Text
Cmd.CommandText = "SELECT market, COUNT(cati_id) as idcnt FROM floridaaddress112 GROUP BY market"
Cmd.Connection = Conn
Read = Cmd.ExecuteReader
While Read.HasRows = True
Read.Read()
RowNumber += 1
Console.WriteLine(Read(0).ToString())
End While

Catch ex1 As Exception
Msg += ex1.Message

Console.WriteLine(Msg)
MsgBox(Msg)
Finally
Conn.Close()
Conn = Nothing
End Try

End Sub
End Module



Thanks!
Joni
Reply With Quote
  #2  
Old 07-30-2012, 09:27 AM
DrPunk's Avatar
DrPunk DrPunk is offline
Senior Contributor

* Expert *
 
Join Date: Apr 2003
Location: Never where I want to be
Posts: 1,285
Default

Seeing as it's a DBF file then I'd suggest trying to connect to it with Microsoft.Jet.OLEDB.4.0 provider rather than FoxPro VFPOLEDB.1.

http://www.connectionstrings.com/dbf-foxpro
__________________
There are no computers in heaven!
Reply With Quote
  #3  
Old 07-30-2012, 09:59 AM
HappyJoni's Avatar
HappyJoni HappyJoni is offline
Centurion
 
Join Date: Jun 2003
Location: New Jersey
Posts: 150
Default

DrPunk,

Thanks for your quick response

Though I'm sure your suggestion is valid, I don't think that the provider I"m using is the issue. Others in my office use the FoxPro VFPOLEDB and it works fine. I really think it's more of something going wrong with my code...
Reply With Quote
  #4  
Old 07-30-2012, 10:05 AM
DrPunk's Avatar
DrPunk DrPunk is offline
Senior Contributor

* Expert *
 
Join Date: Apr 2003
Location: Never where I want to be
Posts: 1,285
Default

I think you might be right.

I don't use DataReaders much. I'm far more of a DataAdapters kind of guy.

But HasRows doesn't do any reading. Read does the reading...
Code:
Read = Cmd.ExecuteReader
If Read.HasRows Then
    Do While Read.Read


    Loop
End If
Read.Close
HasRows doesn't tell it when it is at the end of the resultset, just that it contains some rows, so your While HasRows is making it read after the end of the resultset, hence the error you are seeing. I think.
__________________
There are no computers in heaven!

Last edited by DrPunk; 07-30-2012 at 10:12 AM.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->