c# - 将 SQLite 选择查询转换为字符串数组
问题描述
我有这个代码
public static void GetOnline1()
{
string query = "SELECT online FROM online";
SQLiteCommand myCommand = new SQLiteCommand(query, myConnection);
myConnection.Open();
SQLiteDataReader result = myCommand.ExecuteReader();
if (result.HasRows)
{
while (result.Read())
{
Console.WriteLine(result["online"]);
//result["online"] to string array?
}
}
myConnection.Close();
我如何将结果 [“在线”] 转换为字符串数组?
解决方案
您需要在之前创建一个新的字符串列表if(result.HasRows)
。
var list = new List<string>();
然后在 while 循环中添加result["online"]
到列表中,如下所示。
while(result.Read())
{
list.Add(result["online"].ToString());
}
推荐阅读
- javascript - WebRTC 适配器似乎不适用于 Firefox
- javascript - 在 react/redux 中使用 socket io 显示当前登录的用户信息
- swift - 单击 CallKit 中的应用程序图标时打开应用程序
- python - 使用 Marshmallow 反序列化强制执行严格的字段。日期格式
- sql - SQL子查询的替代方式是什么?
- javascript - 可触摸的不透明度功能在应用程序启动时立即调用
- python - Tensorflow 服务器:我不想为每个会话初始化全局变量
- postgresql - 访问女士,参数化查询,这段代码有什么问题?
- python - Python assert 语句中的比较
- iphone - 在标签栏上制作自定义按钮