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

Brad Marks bradm at blackforestltd.com
Thu Sep 17 21:14:30 CDT 2015


All,

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!

Brad     
 



More information about the dba-VS mailing list