I have an existing Database created in sql server compact edition (inbuilt in visual c# 2010). I need to select and display data from this database on to a form. My code provided gets the form unresponsive.
private void button1_Click(object sender, EventArgs e)
{
SqlDataReader rdr = null;
SqlConnection conn = null;
SqlCommand cmd = null;
using (conn = new SqlConnection(@"Persist Security Info=False;Data Source=ContactName.sdf;database=ContactName"))
{
conn.Open();
string intero = "SELECT Name,Company FROM People";
cmd = new SqlCommand(intero);
rdr = cmd.ExecuteReader();
lbFound.Items.Clear();
while (rdr.Read())
{
lbFound.Items.Add(rdr["Name"].ToString() +
" " + rdr["Company"].ToString());
}
rdr.Close();
conn.Close();
}
}