Solved

Visual Studio 2013 Express Basic Connection string to local DB

Posted on 2014-09-26
2
554 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

733 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