Database Reference
In-Depth Information
Figure 13-5. The Design view of the CommandReader form
5. Now double-click the empty surface of the CommandReader.cs form, and it will
open the code editor window, showing the CommandReader_Load event. Modify
the CommandReader_Load event to look like Listing 13-3.
Listing 13-3. CommandReader.cs
Using System.Data.SqlClient;
private void CommandReader_Load(object sender, EventArgs e)
{
// Create connection
SqlConnection conn = new SqlConnection(@"
server = .\sql2012;
integrated security = true;
database = AdventureWorks");
// Create command
string sql = @"select Name,ProductNumber
from Production.Product";
SqlCommand cmd = new SqlCommand(sql, conn);
txtReader.AppendText("Command created and connected.\n\n");
try
{
// Open connection
conn.Open();
Search WWH ::




Custom Search