Click here to Skip to main content
15,910,471 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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




C#
 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:
C#
int InsertBook(string BookName, string Description, decumal? Price, int? Publisher, int? Category,ref int? PublishDate)


And it didn't success..
Posted

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:
C#
int? thePublishDate = PublishDate;
return Bta.InsertBook(BookName, Description, Price, Publisher, Category, ref thePublishDate);
 
Share this answer
 
Comments
Y.Ahmad 22-May-15 13:57pm    
Yes, there's output parameter, but if I wrote this:

return Bta.InsertBook(BookName, Descpn, Price, Publisher, Category, PublishDate,ref BookID);

This error will appear!

CS1501: No overload for method 'InsertBook' takes 7 arguments
Richard Deeming 22-May-15 13:59pm    
And why do you think that is?

The signature you posted in the question has six arguments. The code you've just posted is trying to pass seven arguments.
Y.Ahmad 22-May-15 14:05pm    
Because Publishdate isn't nullable, and isn't output!
Richard Deeming 22-May-15 14:07pm    
No; because you can't pass seven arguments to a function which only accepts six arguments!
Y.Ahmad 22-May-15 14:06pm    
This's my procedure

CREATE procedure InsertBook

@BookName nvarchar(50) ,
@Description nvarchar(500),
@Price int,
@Publisher int,
@Category int,
@PublishDate int,

@BookID int Output
AS
INSERT INTO Books
VALUES (@BookName,@Description,@Price,@Publisher ,@Category,@PublishDate);
set @BookID=@@Identity
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.

http://stackoverflow.com/questions/6389437/explanation-of-int-vs-int[^]
 
Share this answer
 
Comments
Y.Ahmad 22-May-15 14:02pm    
There's no any nullable value, and the I defined price as int to know where's the wrong.. and I didn't success,

This's my procedure:

CREATE procedure InsertBook

@BookName nvarchar(50) ,
@Description nvarchar(500),
@Price int,
@Publisher int,
@Category int,
@PublishDate int,

@BookID int Output
AS
INSERT INTO Books
VALUES (@BookName,@Description,@Price,@Publisher ,@Category,@PublishDate);
set @BookID=@@Identity

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900