Today I learned how to connect to Microsoft SQL database from ASP.NET page using ADO.NET.
Here is the Page Load method which connects to the database and assigns the values taken from the database to the dropdownlist control.
protected void Page_Load(object sender, EventArgs e)
// SQL Connection
SqlConnection MyConnection = new SqlConnection();
MyConnection.ConnectionString = "Data Source=COMPUTERV22;Initial Catalog=CIMNET2;User ID=sa;Password=manager;";
SqlCommand MyCommand = new SqlCommand();
MyCommand.Connection = MyConnection;
MyCommand.CommandText = "Select * from Employees";
//Open a connection to the database
// SQL Reader, place where rows from database is stored.
MyReader = MyCommand.ExecuteReader();
// Read each record from the database
//Close the connection to the database