Database Reference
In-Depth Information
Figure 15-7. The Design view of the DataViews form
5. Double-click the empty surface of the DataViews.cs form, and it will open the
code editor window, showing the DataViews_Load event. Modify the
DataViews_Load event to look like Listing 15-3.
Listing 15-3. DataViews.cs
Using System.Data.SqlClient;
private void DataViews_Load(object sender, EventArgs e)
{
// Connection string
string connString = @"server=.\sql2012;database=AdventureWorks;Integrated
Security=true";
// Query
string sql = @"select FirstName, MiddleName
from Person.Contact";
// Create connection
SqlConnection conn = new SqlConnection(connString);
try
{
// Create Data Adapter
SqlDataAdapter da = new SqlDataAdapter();
 
Search WWH ::




Custom Search