c# - 如何在 C# 中将查询结果作为字符串返回?
问题描述
下面的查询返回单个 VARCHAR 值,我想将此值作为字符串返回。我该怎么做?
代码片段:
string query = "SELECT " + FieldName + " FROM " + Table4 + " WHERE StartTime=" +
StartTime + " AND SystemId=" + SystemId + '"';
string result = "";
MySqlCommand cmd = new MySqlCommand(query, connection);
var reader = cmd.ExecuteReader();
while (reader.Read())
{
result = ... // set "result" to the output of the query here
}
return result;
}
解决方案
您可以创建一个列表并将值添加到列表中。返回列表后。
推荐阅读
- python - 如何在 python 中将 (10000, 10, 10) 数组转换为 (10000, 100, 1)?
- r - 从 PostgreSQL 查询日期/时间到 R
- flutter - 滚动/跳转到 Flutter GridView 中的正确位置
- javascript - 使用 Jquery 向下滚动 - On Hover
- macos - 如何在 macOS Catalina 上编译 GCC?
- android - 如何通过图片而不是文字分享我想要的信息
- postgresql - PostgreSQL 调用另一个函数
- c++ - 四舍五入的平均值越来越差
- opencl - 非常奇怪的 OpenCL CL_OUT_OF_RESOURCES 行为
- sql - 如何选择玩多种游戏类型的玩家