Retrieve data from a database

Nothing advanced here, I just wanted to store this code snippet somewhere for easy reuse…

SqlConnection conn = new SqlConnection(@"...");
SqlCommand cmd = new SqlCommand("select * from employee", conn);
cmd.CommandType = CommandType.Text;

using (conn)
{
	conn.Open();
	SqlDataReader reader = cmd.ExecuteReader();
	while (reader.Read())
	{
		...
	}
}

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.

This site uses Akismet to reduce spam. Learn how your comment data is processed.