C#GUI LINQ问题

编程入门 行业动态 更新时间:2024-10-13 08:21:11
本文介绍了C#GUI LINQ问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在使用LINQ访问C#程序中的数据时遇到了问题。我已经从访问中上传了数据。但是我们需要创建一个名为MovieFinder的应用程序,用户可以通过输入标题的一部分或导演名称的一部分来选择要观看的电影。那么有人知道该怎么做吗?只需输入部分名称即可获得所有电影?例如:输入The获取电影列表The Avengers,The Godfather,The Graduate。与导演的名字相同,输入spi,以获得斯皮尔伯格导演的所有电影。非常感谢你们。 这是我目前的代码:

I just got a problem on doing my LINQ to access data in C# programs. I already upload the data from access. But here is a requirement we need create an application named MovieFinder in which the user can select movies to view by entering part of the title or part of the director's name. So does anybody know who to do that? Getting all the movies by just enter part of the name? eg: enter "The" get the movie list "The Avengers", "The Godfather", "The Graduate". The same with director's name, by entering "spi", to get all the movies directed by "Spielberg". Thank you guys so much. Here is my current code:

private void searchButton_Click(object sender, EventArgs e) { if (titleradioButton.Checked == true) { string title = Convert.ToString(movietextBox.Text); this.moviesTableAdapter.Fill (this.moviesDataSet.Movies); var moviesTitle = from c in this.moviesDataSet.Movies where c.Title == title orderby c.Genre, c.Director ascending group c by (string)c.Genre; foreach (var group in moviesTitle) { movielistBox.Items.Add("Genre: " + group.Key); foreach(var c in group) movielistBox.Items.Add(c.Title + " directed by " + c.Director + " \nReleased in" + c.ReleaseYear); } } if (directorradioButton.Checked == true) { string director = Convert.ToString(movietextBox.Text); this.moviesTableAdapter.Fill (this.moviesDataSet.Movies); var moviesDirector = from c in this.moviesDataSet.Movies where c.Director == director orderby c.Genre, c.ReleaseYear ascending group c by (string)c.Genre; foreach (var group in moviesDirector) { movielistBox.Items.Add("Genre: " + group.Key); foreach (var c in group) movielistBox.Items.Add(c.Title + " directed by " + c.Director + " \nReleased in" + c.ReleaseYear); } } }

推荐答案

更改此: Change this: where c.Title == title

这个:

And this:

where c.Director == director

对此:

To this:

where c.Title.StartsWith(title)

这个:

And this:

where c.Director.StartsWith(director)

除了 OriginalGriff [ ^ ],使用 In addition to solution1 by OriginalGriff[^], use where c.Title.Contains(title) //and/or where c.Director.Contains(director)

更多: Enumerable.Contains方法 [ ^ ]

更多推荐

C#GUI LINQ问题

本文发布于:2023-11-12 11:02:51,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1581306.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:GUI   LINQ

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!