Database Reference
In-Depth Information
// Execute query via ExecuteReader
SqlDataReader rdr = cmd.ExecuteReader();
while (rdr.Read())
{
txtReader.AppendText("\nProduct: ");
txtReader.AppendText(rdr.GetValue(1) + "\t\t" + rdr.GetValue(0));
txtReader.AppendText("\n");
}
}
catch (SqlException ex)
{
MessageBox.Show(ex.Message + ex.StackTrace, "Exception Details");
}
finally
{
conn.Close();
txtReader.AppendText("Connection Closed.");
}
}
6. To set the CommandReader form as the start-up form, modify the Program.cs
statement:
Application.Run(new CommandScalar ());
to appear as:
Application.Run(new CommandReader());
Build the project, and run it by pressing Ctrl+F5.
7. When the form loads, the result should look like Figure 13-6.
Search WWH ::




Custom Search