Connection works but returns no records

A

auntiejack56

Hi, I have been studying the books (2 ADO.NET and 1 VB.NET) and still
can't work out why the records in the database aren't being read.
Dim sConString As String = "Data Source=.
\SQLEXPRESS;AttachDbFilename=""C:\Active Access Library\FigaroNET
\Figaro\Figaro\FigaroData.mdf"";Integrated Security=True;Connect
Timeout=30;User Instance=True"
Dim conDivisions As New SqlConnection(sConString)
conDivisions.Open()
MessageBox.Show(conDivisions.State.ToString())
Dim sCompanySelect As String = "SELECT * FROM
Entities.tbl1_company"
Dim daCompanies As New SqlDataAdapter(sCompanySelect,
conDivisions)
Dim dsCompanies As New DataSet()
Dim intCompanies As Integer

intCompanies = daCompanies.Fill(dsCompanies, "Companies")

MessageBox.Show("Found " & intCompanies & " records.")

dsCompanies.Clear()
conDivisions.Close()
<<<<

I get an "Open" message from the first MessageBox.Show, and 0 from the
second, even though there are some records in Entities.tbl1_company.

Thanks for any help,

Ray
 
N

Norman Yuan

Are you absolutely sure the table of the database of the USER INSTANCE of
the SQL Server Express have record? How do you know that? Or the database,
which you know there i srecord in that table, is not the database your code
connects to (because you are using USER INSTANCE, and hopefully you know
what is it)?
 
A

auntiejack56

Thanks Norman, you were quite right in suspecting I was using the
wrong database. I have also researched the User Instance option which
has been very helpful,

Ray
 

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

Top