我有這個代碼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();我如何將 result["online"] 轉換為字符串數組?
2 回答

慕碼人8056858
TA貢獻1803條經驗 獲得超6個贊
您需要在之前創建一個新的字符串列表if(result.HasRows)。
var list = new List<string>();
然后添加result["online"]到 while 循環中的列表,如下所示。
while(result.Read())
{
list.Add(result["online"].ToString());
}

犯罪嫌疑人X
TA貢獻2080條經驗 獲得超4個贊
將結果放入List<string>:
var onlineList = new List<string>();
if (result.HasRows)
{
while (result.Read())
{
Console.WriteLine(result["online"]);
onlineList.Add(result["online"].ToString());
}
}
如果您需要將其作為數組,可以使用:onlineList.ToArray()
- 2 回答
- 0 關注
- 269 瀏覽
添加回答
舉報
0/150
提交
取消