using System; using System.Data; // This example needs the // System.Data.SqlClient library using System.Data.SqlClient; using System.Data.SqlTypes; namespace account { public partial class _Default : System.Web.UI.Page { #region Building the connection string string ConnectionString = "Data Source=[SERVER];Initial Catalog=[DATABASE];User Id=[USER];Password=[PASSWORD]"; #endregion #region Try to establish a connection to the database protected void Page_Load(object sender, EventArgs e) { SqlConnection SQLConnection = new SqlConnection(); SQLConnection.ConnectionString = ConnectionString; SQLConnection.Open(); #endregion #region Execute a SQL query // Replace table here with the name of your table string SQLStatement = "SELECT * FROM [table]"; // Create a SqlDataAdapter to get the results as DataTable SqlDataAdapter SQLDataAdapter = new SqlDataAdapter(SQLStatement, SQLConnection); // Create a new DataTable DataTable dtResult = new DataTable(); // Fill the DataTable with the result of the SQL statement SQLDataAdapter.Fill(dtResult); // Loop through all entries foreach (DataRow drRow in dtResult.Rows) { // Spits on text to the screen // the "Name" column Response.Write(drRow["Name"].ToString()); } // We don't need the data adapter any more SQLDataAdapter.Dispose(); #endregion #region Close the database link SQLConnection.Close(); SQLConnection.Dispose(); #endregion } } // end class } // end namespace