使用动态数据库中的成员填充组合框项,C#
我的数据库 db 有一个主键“Artist”和外键“CdTitle”,在一种形式中,用户可以输入信息以添加到数据库中,在另一种形式中,我有一个组合框,我想用名称填充数据库中艺术家的名称,主要是“Artist.Names” 我尝试使用 LINQ 遍历数据库并将查询结果放入组合框中,但它并不像我想象的那样工作。
我的代码是:
var ArtistNames =
from name in formByArtist.db.Artists
select name.Name;
foreach (var element in ArtistNames)
{
comboBox1.Items.Add(element.ToString());
}
My database, db, has as a primary key 'Artist' with foreign key 'CdTitle', in one form a user can enter information to add to the database, in another form, I have a combobox that I want to populate with the names of the artist in the database, primarily 'Artist.Names' I've tried using a LINQ to traverse the database and put the results of the query into the combobox but it's not working like i thought.
the code I have is :
var ArtistNames =
from name in formByArtist.db.Artists
select name.Name;
foreach (var element in ArtistNames)
{
comboBox1.Items.Add(element.ToString());
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
假设你的艺术家有名字和 ID,你可以这样做:
Suposing your Artist have a Name and an Id, you can do this:
从现有示例中,进行如下修改:
From your existing sample, modify as follows: