[dba-VS] Trying to Pull Data from a Local Database via C# code

Gustav Brock gustav at cactus.dk
Fri Sep 18 05:19:50 CDT 2015

Hi Brad

As a starter, you could join our old project Northwind.NET where you will meet some familiar names:


Except for some useful documentation by Shamil, nobody has been working on it since 2009 but still you may find it useful to study. We worked hard to get the reporting right, and for this part alone it can be hard to find other good examples.

Have fun!


-----Oprindelig meddelelse-----
Fra: dba-VS [mailto:dba-vs-bounces at databaseadvisors.com] På vegne af Brad Marks
Sendt: 18. september 2015 04:15
Til: Development in Visual Studio <dba-vs at databaseadvisors.com>
Emne: [dba-VS] Trying to Pull Data from a Local Database via C# code


I am new to Visual Studio and C#.

Recently, I have been experimenting with several small C# programs to better understand C# and to document how to do various tasks.

Earlier this week, I used Visual Studio (2013) to set up a small test Local database (via Visual Studio facilities) and populate it with a few rows of data.

Here is what I did.

Added a new Item "Service-Based Database" named Test1.mdf

Used "Data Sources" to add a new Data Source

Via the Visual Studio "Server Explorer", I added a new table called tlbTest1 with just one column named "Field1"

Used "Show Table Data" to view the new table and then added a small number of rows.

Used "Data Sources" to add a new data source, checked tblTest1 and then dragged this new table to a small Form.

I was then able to view (on the form) the rows that I had added earlier. 

So far, things worked nicely.  I was able to establish a new local database, set up a new table, add data to this table, and then view this data via a form.

Next, I want to figure out how to retrieve the data via C# code.  I have found quite a bit of information on the internet and I have made many attempts, but no success.

After spending an entire day on this issue, I decided to ask the following question.

Does anyone have a simple example of how to pull data from a local database with C# code?

I believe that I have the connection string correct, as it appears that the "connect" statement seems to be working.

Thank You!


More information about the dba-VS mailing list