Start learning with our library of video tutorials taught by experts. Get started

Visual Studio 2010 Essential Training

Connecting your data


From:

Visual Studio 2010 Essential Training

with Walt Ritscher

Video: Connecting your data

A nice improvement for our application would be to store our searches in a database. Visual Studio contains a number of useful data tools. We'll look at the Data Sources window, and the drag-and-drop binding in his movie. I'm inside Visual Studio. I've opened the Solution called InfoReaderData, which contains one project called InfoReaderV4. I've got this MainWindow.xaml file, which is a continuation from the other movies in this chapter. I'm going to take the information when you click on either of these search buttons, and I'm going to store it in the database.
Expand all | Collapse all
  1. 2m 3s
    1. Welcome
      1m 2s
    2. Using the exercise files
      1m 1s
  2. 7m 19s
    1. Understanding the Visual Studio versions
      3m 51s
    2. Setting up your developer computer
      3m 28s
  3. 58m 2s
    1. Creating a Visual Studio project
      4m 58s
    2. Working with Solution Explorer
      6m 32s
    3. Working with big projects
      3m 53s
    4. Taking a tour of the Integrated Developer Environment (IDE)
      8m 36s
    5. Introducing drag-and-drop UI design
      7m 38s
    6. Working with the Properties window
      6m 44s
    7. Looking at Server Explorer
      7m 4s
    8. Exploring the new Help engine
      6m 41s
    9. Setting options for the IDE
      5m 56s
  4. 39m 25s
    1. Creating a simple WPF application
      1m 32s
    2. Building the UI with the editors
      9m 14s
    3. Working with the application code
      3m 37s
    4. Communicating with the web site
      7m 15s
    5. Connecting your data
      8m 4s
    6. Binding to an RSS feed
      5m 4s
    7. Packaging and deploying the application
      4m 39s
  5. 39m 46s
    1. What languages are supported in Visual Studio 2010?
      1m 17s
    2. Exploring basic settings for the Code Editor
      5m 35s
    3. Writing a C# program
      6m 48s
    4. Writing a VB program
      6m 29s
    5. Working with C++
      6m 38s
    6. Working with F Sharp
      6m 9s
    7. Font and color options
      6m 50s
  6. 1h 5m
    1. Formatting your code
      6m 43s
    2. Navigating your code
      7m 44s
    3. Using the Task List
      2m 26s
    4. Commenting your code
      2m 45s
    5. Documenting your code
      8m 26s
    6. Using IntelliSense effectively
      7m 0s
    7. Working with code snippets
      6m 25s
    8. Refactoring your code
      5m 15s
    9. Understanding code generation
      2m 10s
    10. Generating code with T4
      6m 29s
    11. Using the Class View, Class Designer, and Class Diagram tools
      5m 51s
    12. Refactoring VB with CodeRush Xpress
      4m 33s
  7. 1h 11m
    1. Working with project and item templates
      8m 38s
    2. Creating a console application
      7m 5s
    3. Creating a class library
      6m 26s
    4. Creating a web site with ASP.NET
      7m 37s
    5. Creating a rich internet application with Silverlight
      6m 57s
    6. Creating a classic Windows application with Windows Forms
      10m 31s
    7. Creating a dramatic Windows application with Windows Presentation Foundation (WPF)
      4m 41s
    8. Creating a WCF service
      9m 1s
    9. Using an existing WCF service
      6m 38s
    10. Navigation UI designs with the Document Outline view
      3m 41s
  8. 33m 18s
    1. Creating a data project with SQL Project
      6m 24s
    2. Clarifying the confusion on .NET Data
      3m 31s
    3. Using ADO.NET in your application
      6m 50s
    4. Creating typed datasets
      7m 55s
    5. Using the data binding tools
      8m 38s
  9. 30m 13s
    1. Debugging code
      9m 32s
    2. Working with the Watch and other debug windows
      7m 46s
    3. Other debugging techniques
      6m 50s
    4. IntelliTrace historical debugging in Visual Studio Ultimate
      6m 5s
  10. 17m 56s
    1. Understanding Visual Studio editions and test tools
      2m 22s
    2. Verifying your code with unit tests
      8m 58s
    3. Running performance and load tests
      6m 36s
  11. 34m 5s
    1. Building your application
      4m 19s
    2. Customizing the build process with MSBuild
      6m 36s
    3. Setting assembly information
      2m 12s
    4. Deploying a basic Windows application
      2m 19s
    5. Creating an installer with Visual Studio
      7m 39s
    6. Creating a ClickOnce application
      5m 13s
    7. Setting up IIS for deploy
      2m 9s
    8. Deploying a Silverlight or ASP.NET application
      3m 38s
  12. 14m 0s
    1. Understanding source control
      2m 9s
    2. Setting up Team Foundation Server source control
      3m 5s
    3. Using Team Foundation Server source control
      8m 46s
  13. 17m 31s
    1. Understanding the .NET Office integration
      4m 16s
    2. Making a Word 2010 application
      7m 54s
    3. Making an Excel 2010 add-in
      5m 21s
  14. 31m 34s
    1. Understanding the extensibility model in Visual Studio
      2m 17s
    2. Adding external tools to the Tools menu
      4m 42s
    3. Creating macros
      7m 16s
    4. Using the Extension Manager
      5m 1s
    5. Creating an MEF add-in
      7m 9s
    6. Deploying and installing an add-in with VSIX
      5m 9s
  15. 25m 34s
    1. Working with configuration files
      5m 37s
    2. Using the Settings Editor
      7m 30s
    3. Using the Resources Editor
      6m 59s
    4. Localizing your resources
      5m 28s
  16. 1m 17s
    1. Goodbye
      1m 17s

Watch this entire course now—plus get access to every course in the library. Each course includes high-quality videos taught by expert instructors.

Become a member
Please wait...
Visual Studio 2010 Essential Training
8h 9m Intermediate Nov 16, 2010

Viewers: in countries Watching now:

In Visual Studio 2010 Essential Training, author Walt Ritscher demonstrates how to use Visual Studio 2010 Professional to develop full-featured applications targeting a variety of platforms. Starting with an overview of the integrated developer environment, the course covers working with code editors, navigating and formatting code, and deploying applications. Also included are tutorials on running performance and load tests, and debugging code. Exercise files accompany the course.

Topics include:
  • Creating a Visual Studio project
  • Building the user interface
  • Binding to an RSS feed
  • Coding with IntelliSense
  • Creating rich Internet applications with Silverlight
  • Building Windows applications with Windows Forms
  • Integrating with SQL Server
  • Working with Microsoft Office applications
  • Understanding extensibility in Visual Studio
  • Working with data, ADO.NET and datasets
  • Using source control
Subject:
Developer
Software:
ASP.NET Silverlight Visual Studio
Author:
Walt Ritscher

Connecting your data

A nice improvement for our application would be to store our searches in a database. Visual Studio contains a number of useful data tools. We'll look at the Data Sources window, and the drag-and-drop binding in his movie. I'm inside Visual Studio. I've opened the Solution called InfoReaderData, which contains one project called InfoReaderV4. I've got this MainWindow.xaml file, which is a continuation from the other movies in this chapter. I'm going to take the information when you click on either of these search buttons, and I'm going to store it in the database.

Then I'm going to show you your history of your searches over in this list box on the History tab. The first thing I need to do is add a database. To do that, I'm going to go to my project, right-click, and choose Add > Existing Item. Then I'm going to navigate out to my Desktop, find the Exercise Files folder, and look in the Assets folder. Be sure and change this dropdown to show All Files. For today, I'm going to use a compact SQL database.

Then name of this database is History.sdf. So I'll choose this one and click on Add. Now Visual Studio realizes that I've picked a data source. It's asking me if I want to make a special type of data access tool called a DataSet. I'm going to go ahead and say Next on this. Visual Studio then queries my database and shows me a list of all of the tables. In this example, I only have one table with two columns. I will check this first check box, and then verify that I like this DataSet name down here.

If I do, I'll click on Finish. A number of things happened when I click the Finish button. First of all, it made a copy of the History.sdf file in my project. It also added a connection to my Server Explorer. If you don't have Server Explorer opened, open it now. You can find it in the View menu or dock to the side of your window. You can see I now have this History.sdf connection. If I expand this, I can see the tables inside that database. I can even right-click on this History table and choose Show Table Data.

Currently, I have no rows in this table, so let me put two rows in there. I'll come over to this column, and type in "WPF", and hit Enter. Then I'll type in "lynda.com". Press Enter. Then I'll close this window. Not only did it add the database, but it also generated this HistoryDataSet.xsd file, and all of its companion files. Let me double-click on the HistoryDataSet, and show you the designer. This is the TableAdapter that is responsible for loading the data into my table from the database and sending the updated data back to the database.

So you see it has a Fill method. I'm going to use that to get the data. To put a new row in the DataSet, I'm going to add a brand-new query. I'll right-click and choose Add Query. Then I'll click on Next. Then I'm going to come down here and choose Insert. It adds a new row to the table. I'm going to click on Next. I'm going to go ahead and accept the defaults. This is the SQL statement that'll be run against the database. Just choose the defaults and click on Next. Then I get to name my query. Again, I'm going to choose the defaults, InsertQuery.

Now when I'm finished, I click on the Finish button. You'll see at the bottom of the TableAdapter is now InsertQuery. Then the @p1 means that I have to pass some sort of parameter into that query. Now I am ready to do some data binding. Let me switch over to my MainWindow.xaml file. Switch to the History tab, and select the list box. I'm going to click on this Zoom to Fit to make it a little bit easier to see. There is a special window for drag-and-drop data binding available inside Visual Studio.

It's in the Data menu. It's called Show Data Sources. I'm going to go ahead and click on this stick pin, the Auto Hide button. On my machine, it docks itself to the bottom left-hand side of the window. Notice that my DataSet is showing up here, and the table that's inside my DataSet is showing up there as well. Now for drag-and-drop data binding, I can pick this table up and drag it over and drop it on my list box. Before I do though, let me point out my XAML that I have down here. It's only got a few items in here.

Keep an eye on that when I drag this over and drop it on the list box. You see what happened is that Visual Studio added three new lines. It wrote a DisplayMemberPath, what to show; it'll show this column called SearchText. It shows that it's bound to a source. This is the WPF and Silverlight way to set up bindings. This tells WTF to monitor the underlying source and load this list box with whatever data is inside this DataSet. Then I also have a SelectedValuePath for this field here, HistoryID.

That's in case the user selects an item. I can use this as the identifier of the row that they selected. I'm not going to be using that in my demo. I'll choose Debug > Start Debugging, save my changes. Then I'm going to click on the History tab. There, I can see my two items from my database. So I've successfully set up a data binding. The next part of the demo will be when the user types in a string here and clicks on of these buttons, I want to add it to the database and make sure that this list box updates.

To do that, I'm going to switch to the code behind. While I'm inside my designer, I can press F7, which switches me over to the Code view. Now when I did the drag-and-drop binding, Visual Studio wrote a lot of code in the Window_Loaded event. It's very hard to read. So I'm going to replace this with a slightly more readable version. I'm going to delete the code here, by pressing Delete. Then I'm going to take this prewritten code here and cut it and paste it right above the Window_Loaded event.

Then I'm going to uncomment the code by pressing Ctrl+K, Ctrl+U. This is going to create an instance of the DataSet. It's also going to create an instance of that TableAdapter that knows how to load and update and insert my data. I'm going to do that here because I'm going to use it elsewhere in my code. So I'm doing it outside the boundaries of this Loaded event. Then I'm going to take this commented code down here and cut it, Ctrl+X, and paste it in the Loaded event. Then uncomment it, Ctrl+K, Ctrl+U. What this does-- now, I see I have an error here.

I'll click here, and then do a Ctrl+Period. Get the smart tag, and then say, using System.Windows.Data. That will fix my code. What this does is it looks in my XAML, and finds something that was created by Visual Studio called HistoryDataSet. Then it creates a TableAdapter, instantiates one, fills the data set, and then sets up something special called a CollectionViewSource, and then moves to the first row. When I call the SendToBing method, I'm going to insert a new row by calling the ta.InsertQueryp-- that's the query we built earlier today.

We're going to pass in the string from the text box, the search string. Then to make sure that it updates correctly, I'm going to call the ta.Fill, which refills the data and then rebinds to the list box. At this point, I think I'm ready to run the application. I'm going to press F5 to debug the application. Then click Yes. Verify that I only have two items in the list box. Then I'll come over here and type in Silverlight and click the Get RSS button.

There is my RSS coming back from Bing. When I click on the History tab, my new item has been added to the list box. If I were to look inside the database, I'd also see that the data is stored in the database. Now there is one more type of data binding I want to talk about in this chapter. That is called XML binding, and it's the topic of the next movie.

Find answers to the most frequently asked questions about Visual Studio 2010 Essential Training.


Expand all | Collapse all
Please wait...
Q: Which edition of Visual Studio 2010 do I need to follow along in this course?
A: The course is taught with Visual Studio 2010 Professional, but can also be used with the Premium or Ultimate editions. The Express editions of Visual Studio, including Visual Basic 2010 Express, Visual C# 2010 Express, and Visual C++ Express, are not covered in this course.
Q: I'm attempting to download the exercise files for this course, and my virus protection is blocking me from unzipping the downloaded file. Are the files corrupted?
A: The alert is a false-positive message. Your antivirus software is detecting the active code included in the exercise files, which in some ways resembles viral code. There is nothing to be alarmed about and you can ignore the warning. This is common among coding courses and environments.
Share a link to this course
Please wait... Please wait...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.
Upgrade now


Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ.

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

Upgrade now

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.


Mark all as unwatched Cancel

Congratulations

You have completed Visual Studio 2010 Essential Training.

Return to your organization's learning portal to continue training, or close this page.


OK
Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member?

Become a member to like this course.

Join today and get unlimited access to the entire library of video courses.

Get started

Already a member?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any lynda.com page and choose Site preferencesfrom the dropdown menu.

Continue to classic layout Stay on new layout
Welcome to the redesigned course page.

We’ve moved some things around, and now you can



Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked