I am working in Xamarin Form ... I create web service ASMX and SQL Server Database, and it works properly. But when I replaced the query by stored procedures there is an error.
what I do :
First of all,
I create class its name DBConnection.cs
for connection string
public class DBConnection
{
public string ConnectionString
{
get
{
return "Data Source=...........;Initial Catalog=..........;User Id=......; Password=......;";
}
}
}
After that, I create the stored procedure Login
CREATE PROCEDURE [dbo].[Login] (
@UserNameLogin NCHAR (20),
@UserPasswordLogin NCHAR (30)
)
AS
SELECT * FROM [Us] WHERE UserName=@UserNameLogin AND UserPassword=@UserPasswordLogin
RETURN 0
Finally, I used the code-behind to connect
public Result Login(string UserName, string UserPassword)
{
SqlConnection con = new SqlConnection(new DBConnection().ConnectionString);
/// Class for return bool vaulable
Result result = new Result();
try
{
SqlCommand com = new SqlCommand("Login", con);
com.Parameters.AddWithValue("@UserNameLogin", UserName);
com.Parameters.AddWithValue("@UserPasswordLogin", UserPassword);
com.Connection = con;
if (con.State == System.Data.ConnectionState.Closed)
con.Open();
SqlDataReader rd = com.ExecuteReader();
if (rd.HasRows)
{
rd.Read();
result.ValidUser = true;
return result;
}
Where is the problem that System.Data.SqlClient.SqlException (0x80131904): Procedure or function 'Login' expects parameter '@UserNameLogin', which was not supplied.
and how to fix it? did I need configurationManager ? and if it yes how to write the correct code