如何解决最好的重载方法匹配有一些无效的参数数据集

编程入门 行业动态 更新时间:2024-10-08 22:55:13
本文介绍了如何解决最好的重载方法匹配有一些无效的参数数据集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我使用数据集并且我正确地做了所有事情,字段作为数据库字段 但是这个消息总是出现给我: 编译错误 描述:编译服务此请求所需的资源时出错。请查看以下特定错误详细信息并相应地修改源代码。 编译器错误消息:CS1502:'KutubDataSetTableAdapters.BooksTableAdapter.InsertBook(字符串,字符串,十进制?,int?,int?,ref int)的最佳重载方法匹配?)'有一些无效的论点

I work with data set and I did every thing correctly, the fields as the Database fields but always this message appears to me: Compilation Error Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. Compiler Error Message: CS1502: The best overloaded method match for 'KutubDataSetTableAdapters.BooksTableAdapter.InsertBook(string, string, decimal?, int?, int?, ref int?)' has some invalid arguments

int InsertBook(string BookName, string Description, int Price, int Publisher, int Category, int PublishDate) { KutubDataSetTableAdapters.BooksTableAdapter Bta = new KutubDataSetTableAdapters.BooksTableAdapter(); return Bta.InsertBook(BookName, Description, Price, Publisher, Category, PublishDate);} }

我试图用这个:

I tried to use this:

int InsertBook(string BookName, string Description, decumal? Price, int? Publisher, int? Category,ref int? PublishDate)

它没有成功..

And it didn't success..

推荐答案

在传入参数时需要指定 ref 修饰符,但不要重新声明参数类型。 此外,参数传递为 ref 或 out 必须完全匹配声明的类型。你不能将 ref int 传递给 ref int?参数,所以你需要使用临时的本地变量。 试试这个: You need to specify the ref modifier when you pass the parameter in, but you don't re-state the argument types. Also, arguments passed as ref or out must match the declared type exactly. You can't pass a ref int to a ref int? parameter, so you'll to use need a temporary local variable. Try this: int? thePublishDate = PublishDate; return Bta.InsertBook(BookName, Description, Price, Publisher, Category, ref thePublishDate);

查看您的外部过程中的变量Price是否正在传递一个int数据类型,但您的另一个方法是期望可以为空的十进制小数?你不能为一个可空的内容交换一个int。 同样的逻辑适用于你的其他几个参数,特别是int和int?。这些数据类型不同。 stackoverflow/questions/6389437/explanation-of-int-vs-int [ ^ ] Look at your variable Price in your outer procedure you are passing an int datatype but your other method is expecting a nullable decimal, decimal?. You cannot interchange an int for a nullable. And the same logic applies to several of your other parameters, specifically the int and the int?. These are not the same data type. stackoverflow/questions/6389437/explanation-of-int-vs-int[^]

更多推荐

如何解决最好的重载方法匹配有一些无效的参数数据集

本文发布于:2023-06-03 07:24:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/471202.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:最好的   如何解决   参数   方法   数据

发布评论

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

>www.elefans.com

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