Solved

Visual Studio 2013 Express Basic Connection string to local DB

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
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 …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
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 …

809 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