Answered by:
how to read scalar value by linq?

Question
-
User1575078971 posted
i first time using linq to sql
getting a error
Error 1 No overload for method 'spRegisterUser' takes 0 arguments C:\Users\harsh\documents\visual studio 2010\Projects\ecommerce\ecommerce\admin\register\registration.aspx.cs 32 38 ecommerce
can you help me with an explanation !
if (Page.IsValid) { using (ecomerceDataContext dbContext = new ecomerceDataContext()) { string EncriptedPassword = FormsAuthentication.HashPasswordForStoringInConfigFile(txtPassword.Text, "SHA1"); Admin newAdmin = new Admin { username = txtusername.Text, password = EncriptedPassword, name = txtName.Text }; int returnCode = dbContext.spRegisterUser().FirstOrDefault(); if (returnCode == -1) { lblMessage.Text = "Username is already exist! Please Enter another username"; } } }
Monday, December 28, 2015 7:13 AM
Answers
-
User753101303 posted
So "Cannot implicitly convert type 'ecommerce.spRegisterUserResult' to 'int'" means that your function just does NOT return an integer value but a 'ecommerce.spRegisterUserResult' object (which is confirmed by the declaration you used earlier).
So just change the int type so that it uses the actual type returned by your function.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, December 30, 2015 11:22 AM
All replies
-
User1724605321 posted
Hi harshamrita,
The error means that the method "'spRegisterUser'" needs arguments . You need to pass parameters to that method . Please check the definition of method "spRegisterUser" .
Best Regards,
Nan Yu
Monday, December 28, 2015 8:44 AM -
User1575078971 posted
Nan Yu
Hi harshamrita,
The error means that the method "'spRegisterUser'" needs arguments . You need to pass parameters to that method . Please check the definition of method "spRegisterUser" .
Best Regards,
Nan Yu
here is the definition can you explain me how to write parameter ..
[global::System.Data.Linq.Mapping.FunctionAttribute(Name="dbo.spRegisterUser")] public ISingleResult<spRegisterUserResult> spRegisterUser([global::System.Data.Linq.Mapping.ParameterAttribute(DbType="VarChar(50)")] string username, [global::System.Data.Linq.Mapping.ParameterAttribute(DbType="VarChar(50)")] string password, [global::System.Data.Linq.Mapping.ParameterAttribute(DbType="Char(50)")] string name) { IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())), username, password, name); return ((ISingleResult<spRegisterUserResult>)(result.ReturnValue)); }
sorry for this amateur level of question
Monday, December 28, 2015 9:46 AM -
User954927490 posted
Hi ,
this shows that is function is expecting three string type parameters
spRegisterUser( string username, string password,string name)
so pass these three values and you will be good,
let me know in case of any other issueMonday, December 28, 2015 10:05 AM -
User1575078971 posted
Hi ,
this shows that is function is expecting three string type parameters
spRegisterUser( string username, string password,string name)
so pass these three values and you will be good,
let me know in case of any other issuethis give several errors
error
Error 1 Invalid expression term 'string' C:\Users\harsh\documents\visual studio 2010\Projects\ecommerce\ecommerce\admin\register\registration.aspx.cs 34 74 ecommerce Error 2 Invalid expression term ',' C:\Users\harsh\documents\visual studio 2010\Projects\ecommerce\ecommerce\admin\register\registration.aspx.cs 34 82 ecommerce Error 3 ; expected C:\Users\harsh\documents\visual studio 2010\Projects\ecommerce\ecommerce\admin\register\registration.aspx.cs 34 82 ecommerce Error 4 ; expected C:\Users\harsh\documents\visual studio 2010\Projects\ecommerce\ecommerce\admin\register\registration.aspx.cs 34 84 ecommerce Error 5 Identifier expected; 'string' is a keyword C:\Users\harsh\documents\visual studio 2010\Projects\ecommerce\ecommerce\admin\register\registration.aspx.cs 34 100 ecommerce Error 6 Invalid expression term ')' C:\Users\harsh\documents\visual studio 2010\Projects\ecommerce\ecommerce\admin\register\registration.aspx.cs 34 111 ecommerce Error 7 ; expected C:\Users\harsh\documents\visual studio 2010\Projects\ecommerce\ecommerce\admin\register\registration.aspx.cs 34 111 ecommerce Error 8 Only assignment, call, increment, decrement, and new object expressions can be used as a statement C:\Users\harsh\documents\visual studio 2010\Projects\ecommerce\ecommerce\admin\register\registration.aspx.cs 34 74 ecommerce Error 9 The name 'username' does not exist in the current context C:\Users\harsh\documents\visual studio 2010\Projects\ecommerce\ecommerce\admin\register\registration.aspx.cs 34 74 ecommerce
Monday, December 28, 2015 11:23 AM -
User753101303 posted
Hi,
What was shown is a function declaration. At call time the type is not given. So it could be based on your current code something such as:
int returnCode=dbContext.spRegisterUser(newAdmin.username,newAdmin.password,newAdmin.name).FirstOrDefault();
You may want to still read some tutorials such as http://www.csharp-station.com/Tutorial/CSharp/SmartConsoleSetup.aspx
Monday, December 28, 2015 12:02 PM -
User1575078971 posted
Hi,
What was shown is a function declaration. At call time the type is not given. So it could be based on your current code something such as:
int returnCode=dbContext.spRegisterUser(newAdmin.username,newAdmin.password,newAdmin.name).FirstOrDefault();
You may want to still read some tutorials such as http://www.csharp-station.com/Tutorial/CSharp/SmartConsoleSetup.aspx
I am using your code and in submit run time error occur.
Monday, December 28, 2015 4:35 PM -
User753101303 posted
You are using Integrated Security=SSPI (or an equivalent option in your connection string) so your web site tries to connect with the Windows account that runs the web site It works with VS as it runs under your own Windows account. See https://msdn.microsoft.com/en-us/library/ms144284.aspx for SQL Server authentication options.
How to fix this depends what you want. Basically:
- you can use a SQL Server account (enable this on the SQL side and so you'll use User Id=xxx;Password=xxx in your connection string rather than Integrated Security=SSPI) which is likely the simplest option
- or you could create a Windows account, configure your IIS app to use this account and so as result you would use a single Windows account to run your web app, access SQL Server and possibly network shares used by your applicationMonday, December 28, 2015 9:38 PM -
User1575078971 posted
thanks for your help but there is one more compile time error now in your line of code
code line
int returnCode = dbContext.spRegisterUser(newAdmin.username, newAdmin.password, newAdmin.name).FirstOrDefault();
Error 1 Cannot implicitly convert type 'ecommerce.spRegisterUserResult' to 'int' C:\Users\harsh\documents\visual studio 2010\Projects\ecommerce\ecommerce\admin\register\registration.aspx.cs 34 43 ecommerce
i try to solve it by convert.toInt32 but it didn't work either
it give a run time error
thanks for your valuable timeTuesday, December 29, 2015 3:28 PM -
User753101303 posted
So "Cannot implicitly convert type 'ecommerce.spRegisterUserResult' to 'int'" means that your function just does NOT return an integer value but a 'ecommerce.spRegisterUserResult' object (which is confirmed by the declaration you used earlier).
So just change the int type so that it uses the actual type returned by your function.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, December 30, 2015 11:22 AM