You got the SQL statement right, at the end your SQLDataSource will look something like this:
<asp:SqlDataSource
id="SqlDataSource1"
runat="server"
DataSourceMode="DataReader"
ConnectionString="Data Source=localhost;Integrated Security=SSPI;Initial Catalog=Northwind;"
SelectCommand="SELECT userName from tblUser">
</asp:SqlDataSource>
Note: You may want to use a connection string located in your config file:
ConnectionString="<%$ ConnectionStrings:MyNorthwind%>"
Also, you could also try to execute this query without using a SQLDataSource since it sounds like you will not be binding the result to a control. For example:
using (SqlConnection connection = new SqlConnection(
connectionString))
{
SqlCommand command = new SqlCommand(
"SELECT userName from tblUser", connection);
connection.Open();
SqlDataReader reader = command.ExecuteReader();
try
{
while (reader.Read())
{
// check if reader[0] has the name you are looking for
}
}
finally
{
// Always call Close when done reading.
reader.Close();
}
}