DataTable has now rows in it after fill

G

Guest

I am ruinning this in the global.asa VIA Visual Studio VB .NET (framework 1.1)

I have a access database with a table called tblCounters with a feild called
Counters
with on row of data in it with a number. When I run the following code

Imports System.Data
Imports System.Data.OleDb

Sub Session_Start......
Dim dbconn As OleDbConnection
Dim dbasp As OleDbDataAdapter
Dim dbcmd As OleDbCommandBuilder
Dim dbdsn As New Dataset("tblCounters")
Dim dbtab As New DataTable("Counters")
Dim strcon As String
Dim strsql As String
Dim count As Double

Application.Lock()
strcon = "PROVIDER=Microsoft.Jet.4.0; DATA Source=C:\Folder\db1.mdb; User
id=admin;password=;"
strsql = "Select * From tblCounter"
dsconn = New OleDbConnection(strcon)
dbadp = New OleDbDataAdapter(strsql, dbconn)
dbcmd = New OleDbCommandBuilder(dbadp)
dbadp.Fill(dbdsn, "Counters")

At this point I should have filled the dataset dbdsn with a table called
"Counters" with one row of data, right? When I try and run this code

cnt = dbdsn.Rows(0).Item("Counters")

I get an error that my table has no rows.
When I look in the locals window under dbtab, the rows say 0 also?

Any suggestions?

Thanks
 
M

Marina Levit [MVP]

You are instnating a connection called 'dsconn', but you are using a
connection called 'dbconn', which from the looks of it, never gets
instantiated. I don't know where 'dsconn' is declared, not in the block you
pasted.

Also, there is no way you could say 'dbdsn.Rows...', because a dataset does
not have a Rows property.

I would confirm that you are connection to the database you think you are
connecting to, and that this table does indeed have rows in the database.
 
G

Guest

I did not cut and past, I typed this code so
dsconn should be dbconn
Dim dbasp As OleDbDataAdapter should be Dim dbadp As OleDbDataAdapter
cnt = dbtab.Rows(0).Item("Counters")

Do I have to name the table somewhere when I read it?
 
M

Marina Levit [MVP]

Well, you are filling a dataset called 'dbdsn'. But trying to get data out
of a datatable called 'dbtab'? It's one or the other. Either you fill the
dataset and look in the dataset after for data, or you fill the datatable
and look for your data in the datatable. But you are putting data in one
object, but expecting it to appear in the other?

I think you need to show your actual code, because you have several mistakes
already, and it's hard to help you if we can't even tell what the actual
code is.
 
G

Guest

found it, I needed to add

dbtab = dbdsn.tables("Counters")

Thanks.

Sometimes you cant see the trees because of the forest!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,162
Latest member
GertrudeMa
Top