c# MySql数据列表

本文关键字:列表 数据 MySql | 更新日期: 2023-09-27 18:03:40

基本上我想做的是从表中读取数据,然后将该数据添加到相应的列表

例如

List<int> value;
SELECT Values_To_Add FROM table
value.add(Values_To_Add)

显然使用了正确的c# MySql语法。我该怎么做呢?

c# MySql数据列表

我认为像下面这样的东西可能是你正在寻找的:

List<int> values = new List<int>();
string sql = "SELECT Values_To_Add FROM table";
command.CommandText = sql;
MySqlDataReader reader = command.ExecuteReader();
while(reader.Read())
{
  values.Add(reader["Values_To_Add "]);
}

你可能会想谷歌关于设置MySqlReader等

希望有帮助,这应该是一个开始

try

List<int> values;
var result = from value in table
             select value;
foreach(var item in result) values.Add(item);

考虑使用SQLDataReader类。

在研究之后,你应该能够使用数据阅读器从你的表中读取行,然后将它们添加到你的列表:)

教程:http://csharp-station.com/Tutorial/AdoDotNet/Lesson04

MSDN: http://msdn.microsoft.com/en-GB/library/system.data.sqlclient.sqldatareader.aspx