Tutorial RSS
 
Navigator: Home - Retrieve - Retrieve data from SQL Server 2005

Retrieve data from SQL Server 2005

Retrieve data from SQL Server 2005


If you're looking for a really good web host, try Server Intellect - we found the setup procedure and control panel, very easy to adapt to and their IT team is awesome!


In this example we're going to load data from the Datawarehouse table. The database we're connecting to is already established in the connection string. The connString is an entry in the Web.Config file and will look like this:

<appSettings>
<add key="connString" value="data source=yourIPaddress;User ID=User; Password=Pass;initial catalog=datahouse"/>
</appSettings>



The method to actually retrieve the data using a data reader will look like this:
public void LoadData()

{
SqlCommand cmd = new SqlCommand("Select * From Datawarehouse", new SqlConnection(ConfigurationManager.AppSettings["connString"]));
cmd.Connection.Open();
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
DataTitle.Text = dr["DataTitle"].ToString();
DataDescription.Content = dr["DataDescription"].ToString();
DataKeywords.Content = dr["DataKeywords"].ToString();
}
else
{

}
cmd.Connection.Close();
cmd.Connection.Dispose();
dr.Close();
}


It's equally important to close and dispose of the connection and connection object.

Try Server Intellect for Windows Server Hosting. Quality and Quantity!


411asp.net123aspxDotNetFreaksServer Intellect