You are here
Home > Programming > Existing Data And Visual Studio LightSwitch

Existing Data And Visual Studio LightSwitch

Fallback Image

lightswitch existing dataExisting Data – LightSwitch has shown us this week how easy it is to create a fully data aware application in a very short amount of time and with minimal developer effort. But what about adding existing data?

I received a message from a reader in Johannesburg this week. His company used an Access database for one of their applications, but needed to migrate away from Access (probably because the data grew large enough to warrant the use of SQL). They had already created the SQL database and migrated the data, and now needed to quickly create a user interface.

His question to me was what technology he could use to create a GUI in the shortest amount of time, without having to learn how to program. Obviously I suggested LightSwitch.

Add Your Existing Data

You might wonder how to add your existing database to a LightSwitch application? This week we have seen that data is what drives LightSwitch. Adding an existing data source is really easier than you think.

add existing data source

From the Visual Studio Solution Explorer, right click on data sources and select ‘Add Data Source…’ from the context menu.

choose data source

For the purposes of this post, I’ll just be using an existing SQL Database, but you can connect to different sources should you wish.

choose existing data source

On the next screen we will select Microsoft SQL Server.

connection properties

Specify your connection details to your server and select the existing database you wish to use. (You probably know where this is going right?)

choose database objects

The next screen allows you to select tables and views.

datasource objects

Seeing as I only want Sales Order data from my existing database, I expand the Tables node and select the appropriate tables for Sales Order Header and Detail data.

Datasource added

Clicking on Finish will add your data source under the Data Sources folder in Solution Explorer and add the table diagrams to your designer (complete with relationship if it finds one).

add screen

The next step is to add a screen to represent your data. From here on out, it is old hat. Exactly as in the previous articles, you configure your screens as you prefer.

add screen data

I have master / detail data to represent, so the best screen for me would be to add the List and Details Screen. Select the data source table (I added the Master table) and check the master and details as additional data to include.

screen data added

Your designer now lists the data bound controls for your screen.

existing data linked to screen

Click on run and see LightSwitch work it’s magic with your existing data source. Under the sales orders column on the left of my application, I can see all the sales order numbers. Clicking on a sales order number populates the data on the sales order data fields to the right. At the very bottom, the sales order details are displayed in the data grid.

Adding existing data to your LightSwitch application is just as easy (if not easier) as creating a new LightSwitch application with a new data source.I hope that you enjoy exploring LightSwitch as much as I do. If you missed my previous articles on LightSwitch, you can read them at the following links:

Visual Studio LightSwitch – True Power Lies In Simplicity

Extending LightSwitch – Deeper Down The Rabbit Hole

LightSwitch Data – Fleshing Out Your Application

LightSwitch Themes – A Change Is As Good As A Holiday

Until next time, happy exploring!

Michael WashingtonImage Reference

Dirk Strauss
Dirk is a Software Developer from South Africa. He loves all things Technology and is slightly addicted to Jimi Hendrix. Apart from writing code, he also enjoys authoring books and articles. "I love sharing knowledge and connecting with people from around the world. It's the diversity that makes life so beautiful." Dirk feels very strongly that pizza is simply not complete without Tabasco, that you can never have too much garlic, and that cooking the perfect steak is an art he has almost mastered.

Similar Articles