Solved

Visual Studio 2013 Express Basic Connection string to local DB

Posted on 2014-09-26
2
563 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

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 …
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…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

734 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