简体   繁体   English

无法隐式转换类型'System.Collections.Generic.List<valueobjectlayer.booksval> '到'int'</valueobjectlayer.booksval>

[英]Cannot implicitly convert type 'System.Collections.Generic.List<ValueObjectLayer.booksVAL>' to 'int'

I'm trying to make a 3 layered C# Library Management project.我正在尝试制作一个 3 层 C# 图书馆管理项目。

I'm trying to select a book from bookDAL (dataacceslayer) through booksBLL(businesslogiclayer and show it on winforms.我正在尝试 select 一本从 bookDAL(dataacceslayer)到 bookBLL(businesslogiclayer)的书,并在 winforms 上显示。

i get this error message on BLL error我收到有关 BLL错误的此错误消息

DAL:达尔:

    public static List<booksVAL> BookSelect(string x)
    {
        List<booksVAL> sonuc = new List<booksVAL>();
        OleDbCommand cmdkitaplistele = new OleDbCommand("select * from books where id = " + Int32.Parse(x) + " ", dbConnection.conn); // 
        if (cmdkitaplistele.Connection.State != ConnectionState.Open) // bağlantı açık değise
        {
            cmdkitaplistele.Connection.Open(); // bağlantıyı aç
        }

        OleDbDataReader dr = cmdkitaplistele.ExecuteReader(); // sorgu sonuçlarını data reader ile oku
        while (dr.Read())
        {
            booksVAL book = new booksVAL();
            book.bookId = int.Parse(dr["id"].ToString());
            book.bookName = dr["bookname"].ToString();
            book.bookAuthor = dr["authorname"].ToString();
            book.bookPagecount = dr["pagecount"].ToString();
            book.bookDatepublished = dr["datepublished"].ToString();
            book.bookIsavailable = dr["isavailable"].ToString();
            book.bookCategory = dr["category"].ToString();
            sonuc.Add(book);
        }
        dr.Close();
        return sonuc;
    }

BLL: BLL:

public static int BookSelect(string x)
{
    return booksDAL.BookSelect(x);

Form:形式:

public partial class bookupdateForm : Form
{
   booksForm f1;
    public bookupdateForm(booksForm frm1)
    {
        InitializeComponent();
        this.f1 = frm1;
        booksBLL.BookSelect(f1.selectedlabel.Text); // selectedlabel comes from another form, it works

    }
}

Problem is here:问题在这里:

public static int BookSelect(string x)
{
    return booksDAL.BookSelect(x);
}

Change return type int to List<booksVAL> :将返回类型int更改为List<booksVAL>

public static List<booksVAL> BookSelect(string x)
{
    return booksDAL.BookSelect(x);
}

无法隐式转换类型 'System.Collections.Generic.List<object> ' 到 'System.Collections.Generic.IEnumerable<int><div id="text_translate"><p> 我想构建一个 function,它接受一个非负整数和字符串的列表,并返回一个过滤掉字符串的新列表。</p><p> 与此类似:</p><pre> ListFilterer.GetIntegersFromList(new List<object>(){1, 2, "a", "b"}) => {1, 2} ListFilterer.GetIntegersFromList(new List<object>(){1, 2, "a", "b", 0, 15}) => {1, 2, 0, 15}</pre><p> 为此,我执行了以下操作:(评论显示了最初的尝试)</p><pre> using System.Collections; using System.Collections.Generic; using System.Linq; public class ListFilterer { public static IEnumerable<int> GetIntegersFromList(List<object> listOfItems) { foreach (var item in listOfItems) { if(item is string) { listOfItems.Remove(item); } } // return listOfItems; <- Original attempt return listOfItems.ToList(); } }</pre><p> 这给出了标题中的错误:</p><pre> src/Solution.cs(16,13): error CS0266: Cannot implicitly convert type 'System.Collections.Generic.List<object>' to 'System.Collections.Generic.IEnumerable<int>'. An explicit conversion exists (are you missing a cast?)</pre><p> 所以我添加了我认为是正确的转换.ToList()但它最终没有做任何事情并且仍然提供相同的错误。 我对此感到困惑,因为在搜索和查看我认为类似的问题后,我仍然没有找到正确的方法来转换它,并且由于我对 Linq 和 Enumerable 的经验不足,我不确定去哪里找。</p><p> 任何帮助将不胜感激,谢谢你的时间</p></div></int></object> - Cannot implicitly convert type 'System.Collections.Generic.List<object>' to 'System.Collections.Generic.IEnumerable<int>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法隐式转换类型 'System.Collections.Generic.List<object> ' 到 'System.Collections.Generic.IEnumerable<int><div id="text_translate"><p> 我想构建一个 function,它接受一个非负整数和字符串的列表,并返回一个过滤掉字符串的新列表。</p><p> 与此类似:</p><pre> ListFilterer.GetIntegersFromList(new List<object>(){1, 2, "a", "b"}) => {1, 2} ListFilterer.GetIntegersFromList(new List<object>(){1, 2, "a", "b", 0, 15}) => {1, 2, 0, 15}</pre><p> 为此,我执行了以下操作:(评论显示了最初的尝试)</p><pre> using System.Collections; using System.Collections.Generic; using System.Linq; public class ListFilterer { public static IEnumerable<int> GetIntegersFromList(List<object> listOfItems) { foreach (var item in listOfItems) { if(item is string) { listOfItems.Remove(item); } } // return listOfItems; <- Original attempt return listOfItems.ToList(); } }</pre><p> 这给出了标题中的错误:</p><pre> src/Solution.cs(16,13): error CS0266: Cannot implicitly convert type 'System.Collections.Generic.List<object>' to 'System.Collections.Generic.IEnumerable<int>'. An explicit conversion exists (are you missing a cast?)</pre><p> 所以我添加了我认为是正确的转换.ToList()但它最终没有做任何事情并且仍然提供相同的错误。 我对此感到困惑,因为在搜索和查看我认为类似的问题后,我仍然没有找到正确的方法来转换它,并且由于我对 Linq 和 Enumerable 的经验不足,我不确定去哪里找。</p><p> 任何帮助将不胜感激,谢谢你的时间</p></div></int></object> - Cannot implicitly convert type 'System.Collections.Generic.List<object>' to 'System.Collections.Generic.IEnumerable<int> 无法隐式转换类型&#39;System.Collections.Generic.List <int> &#39;到&#39;int&#39; - Cannot implicitly convert type 'System.Collections.Generic.List<int>' to 'int' 无法将类型&#39;System.Collections.Generic.List&#39;隐式转换为&#39;string&#39; - Cannot implicitly convert type 'System.Collections.Generic.List' to 'string' 无法隐式转换类型System.Collections.Generic.List <char> - cannot implicitly convert type System.Collections.Generic.List<char> 无法隐式转换类型&#39;System.Collections.Generic.list <fooClass> &#39;到&#39;System.Collections.Generic.List <T> - Cannot Implicitly convert type 'System.Collections.Generic.list<fooClass>' to 'System.Collections.Generic.List<T> 无法隐式转换类型&#39;System.Collections.Generic.List <AnonymousType#1> &#39;到&#39;System.Collections.Generic.List - Cannot implicitly convert type 'System.Collections.Generic.List<AnonymousType#1>' to 'System.Collections.Generic.List 无法隐式转换类型&#39;System.Collections.Generic.List <MyProduct> &#39;到&#39;System.Collections.Generic.List <T> - Cannot implicitly convert type 'System.Collections.Generic.List<MyProduct>' to 'System.Collections.Generic.List<T> 如何修复“无法将类型System.Collections.Generic.List &lt;&gt;隐式转换为System.Collections.Generic.List &lt;&gt;” - How to fix 'Cannot implicitly convert type System.Collections.Generic.List<> to System.Collections.Generic.List<>' 无法隐式转换类型'System.Collections.Generic.List<x> ' 到 'System.Collections.Generic.List<y> '</y></x> - Cannot implicitly convert type 'System.Collections.Generic.List<x>' to 'System.Collections.Generic.List<y>' 无法将类型&#39;string&#39;隐式转换为System.Collections.Generic.List <int> &#39; - Cannot implicitly convert type `string' to `System.Collections.Generic.List<int>'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM