There are plenty of ways to do this; look at tutorials like:
Introduction to SqlClient
A typical code example to just return a data table might look like:
public static DataTable GetTable(string tableName, string connectionString)
{
using (SqlConnection myConnection = new SqlConnection(connectionString))
{
using (SqlCommand myCommand = new SqlCommand(tableName))
{
myCommand.Connection = myConnection;
myCommand.CommandType = CommandType.TableDirect;
using (SqlDataReader reader = myCommand.ExecuteReader())
{
DataTable table = new DataTable();
table.Load(reader);
return table;
}
}
}
}
Note the use of the using keyword. This will ensure your connection is disposed when you are finished with it.
There's example code for obtaining a DataSet here.
You can also vary how you execute your command; you can use myCommand.CommandType = CommandType.Text
and set the CommandString to "SELECT * FROM myTable"
. You can also use CommandType.StoredProcedure
and use the name of a stored procedure.
You might also want to look at abstracting all of this away using one of the many solutions available. Microsoft have the Application Data blocks, Entity Framework, and there are plenty of other alternatives.