Database Reference
In-Depth Information
// Create connection
SqlConnection conn = new SqlConnection(connString);
try
{
// Open connection
conn.Open();
// Create command
SqlCommand cmd = new SqlCommand(sql, conn);
// Create data reader
SqlDataReader rdr = cmd.ExecuteReader();
// Loop through result set
while (rdr.Read())
{
// Add to listbox - one row at a time
lbxProduct.Items.Add(rdr[0]);
}
// Close data reader
rdr.Close();
}
catch (SqlException ex)
{
MessageBox.Show(ex.Message + ex.StackTrace);
}
finally
{
conn.Close();
}
}
7. Build the project, and run the DataLooper form by pressing Ctrl+F5. Your
results should look like Figure 14-2.
 
Search WWH ::




Custom Search