【发布时间】:2015-12-23 11:17:43
【问题描述】:
我是 C# 新手,需要一点帮助。我想从 csv(分号分隔)数据库中导入一个包含三列的表。然后我想遍历表的所有行,获取所有具有“值”的行,然后根据“值”显示复选框或某种类型的多选按钮。我不知道该怎么做,所以我刚开始尝试从数据库中导入数据。这是我的代码:
class Nettstasjoner
{
public string NS { get; set; }
public string Sek { get; set; }
public string Radial { get; set; }
public string Value { get; set; }
Value = "H812"; //this will be set from a button later
static void Main(string[] args)
{
IEnumerable<string> strCSV =
File.ReadLines(@"C:\Users\thomoe\Desktop\SMSvarsel\nsdatabase.csv");
var results = from str in strCSV
let tmp = str.Split(';')
select new
{
NS = tmp[0],
Sek = tmp[1],
Radial = tmp[2]
};
foreach (var tmp in results)
{
//here I need to select all rows with the Value value in it and make a checkbox or something with the captin from the row NS(tmp[0]).
}
}
}
我对其他方法非常开放,包括 MVVM,我刚刚尝试通过谷歌搜索做我能做的事情等等。现在我被困住了。非常感谢您的帮助,请在回答时非常具体;)我对 C# 的理解仍然很薄 :)
【问题讨论】: