Solved

Visual Studio 2013 Express Basic Connection string to local DB

Posted on 2014-09-26
2
567 Views
Last Modified: 2014-10-05
Hi Experts
I have just started using Visual Studio 2013 Express Basic.
I have created a local database in folder C:\garage\garagedatabase.mdf and has a table customer
I have tried the following code but no success

Imports System.Data.SqlClient

   Private DScustomer As DataSet
    Private DTCustomer As DataTable



  Private cs As New SqlConnection("Data Source(LocalDB)\v11.0; AttachDbFileName=C:\garage\garageDatabase.mdf; Integrated Security=True" )

    Private DAcutomer As New SqlDataAdapter(" SELECT * FROM dbo.Customer ", cs)

    cs.Open()
        DACustomer.Fill(dscustomer, "customer")
        cs.Close()


        DTCustomer = DScustomer.Tables("customer")
        DataGridView1.DataSource = DTCustomer
   

it does not evaluate the expression
please help
Thanks
0
Comment
Question by:b001
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 250 total points
ID: 40347234
You do not need a DataSet when you have only one DataTable. You can directly fill the DataTable. When you have only one table, or many tables without DataRelations objects to link them, the DataSet is simply using resources for nothing. Unfortunately, this is a mistake that is everywhere on the Internet.

 DACustomer.Fill(DTCustomer)

Also, you do not need to Open and Close the Connection object when you use Fill. It does it for you.

But this will probably not correct your problem.

What do you mean exactly by it does not evaluate the expression.

Do you get an exception? Do you end up with no data at all? If so, are you sure there is data in the table. Do you get a value higher than zero if you ask for DTCustomer.Rows.Count?

Something else?
0
 
LVL 75

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 250 total points
ID: 40347288
You'll want to keep www.connectionstrings.com handy--it keeps track of all the various connection strings you'll use when you code. In particular, your connection string is slightly off. Going by the site:

Private cs As New SqlConnection("Server=(localdb)\v11.0;Integrated Security=true; AttachDbFileName=C:\garage\garageDatabase.mdf; Integrated Security=True" )

Open in new window

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

615 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question