Here is a google search that gives you instructions on how to achieve this:
Google[
^]
If you are creating a WPF application:
Data Binding Overview[
^]
Update 1:
Based on your connection string I assume that you are working on an ASP.Net application.
You'll probably want to use the databinding features of asp.net.
SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=D:\Guru\HRP\App_Data\hrp.mdf;Integrated Security=True;User Instance=True");
Here is one article here on CP
Mastering ASP.NET DataBinding[
^] that you may find useful,
This
Google search[
^], provides you with a ton of reading material.
Example from documentation[
^]:
private static void ReadOrderData(string connectionString)
{
string queryString =
"SELECT OrderID, CustomerID FROM dbo.Orders;";
using (SqlConnection connection = new SqlConnection(
connectionString))
{
SqlCommand command = new SqlCommand(
queryString, connection);
connection.Open();
SqlDataReader reader = command.ExecuteReader();
try
{
while (reader.Read())
{
Console.WriteLine(String.Format("{0}, {1}",
reader[0], reader[1]));
}
}
finally
{
reader.Close();
}
}
}
Usually you don't want to reuse the same connection object instance. Create a new SqlConnection on each request.
Regards
Espen Harlinn