zhshqzyc
asked on
Get a particular column value using C#
Hello,
I want to to retrieve a column value from a table.
Thanks for help.
I want to to retrieve a column value from a table.
Thanks for help.
string commandtext = "select column1 FROM [t1]";
string[] list = DataAccess.ExecuteReader(commandtext).ToArray();
public static List<string> ExecuteReader(string commandtext)
{
List<string> sVal = new List<string>();
try
{
using (SqlConnection cnn = new SqlConnection(conn))
{
cnn.Open();
using (SqlCommand cmd = new SqlCommand())
{
cmd.Connection = cnn;
cmd.CommandType = CommandType.Text;
cmd.CommandText = commandtext;
using (SqlDataReader reader = cmd.ExecuteReader())
{
// here need help.
}
}
cnn.Close();
}
}
catch (Exception ex)
{
}
return sVal.ToList().Distinct().ToList();
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.