Database Reference
In-Depth Information
Figure 17-8.
The Design view of the RetrieveText form
5.
Next, insert the code in Listing 17-6 into
RetrieveText.cs
. You can access
RetrieveText.cs
by right-clicking
RetrieveText.cs
and selecting View Code,
which will take you to the Code view.
Listing 17-6.
RetrieveText.cs
using System.Data;
using System.Data.SqlClient;
string textFile = null;
char[] textChars = null;
SqlConnection conn = null;
SqlCommand cmd = null;
SqlDataReader dr = null;
public RetrieveText()
{
InitializeComponent();
// Create connection
conn = new SqlConnection(@"data source = .\sql2012;integrated security = true;
initial catalog = SQL2012Db;");
// Create command
cmd = new SqlCommand(@"select textfile, textdata
from TextTable", conn);