Solved

Visual Studio 2013 Express Basic Connection string to local DB

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

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Performance enhancement 39 26
Crystal Report for VS2013 17 40
Hide Tab Page 3 18
Create XML 5 33
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

706 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now