Database Reference
In-Depth Information
{
listBox1.Items.Add(String.Format("{0} {1}", rdr[0], rdr[1]));
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
}
When the code is in place, run the application. When Form1 appears, click the button; doing so
should quickly display in the list box the first name and last name of the contacts from the Contact table.
As you can see, the code is the same as if you were querying a local SQL Server database, except for the
connection string.
Connecting from the Entity Framework
This example uses the ADO.NET Entity Framework and lets it handle your connection. Follow these
steps:
1.
Fire up Visual Studio 2010, and create a new Windows Forms Application
project. For this simple example, you can use whatever project name you like.
2.
Right-click the project in the Solution Explorer window, and select Add
New
Item from the context menu. Doing so brings up the Add New Item dialog.
3.
Select the ADO.NET Entity Data Model data template, as shown in Figure 3-13.
Figure 3-13. Adding an ADO.NET entity data model
Search WWH ::




Custom Search