我正在使用 ExecuteScalar
获取一列:
cmd.commandtext = "select rodeuser from customer_db_map";
string rodecustomer = cmd.executescalar;
但我需要得到不止一列,例如:
cmd.commandtext = "select rodeuser,username,password from customer_db_map";
我需要一个字符串中的每一列:
string rodecustomer = cmd.ExecuteScalar();
string username= cmd.ExecuteScalar();
string password = cmd.ExecuteScalar();
但这是不可能的。这是如何实现的?
最佳答案
ExecuteScalar
执行查询,并返回查询返回的结果集中第一行的第一列。其他列或行将被忽略。
要实现这一点,您需要使用 SqlCommand.ExecuteReader
方法
关于c# - 如何使用 ExecuteScalar 检索多个列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6291716/