在Xamarin中使用网络服务的存储过程 [重复]

问题描述 投票:0回答:1

我在Xamarin表格...... 我创建了Web服务ASMX和SQL Server数据库,并正常工作。但是,当我替换了存储过程的查询,有一个错误。

我做了什么。

首先。

我创建的班级名称为 DBConnection.cs 对于连接字符串

  public class DBConnection
    {
        public string ConnectionString
        {
            get
            {
                return "Data Source=...........;Initial Catalog=..........;User Id=......; Password=......;";
            }
        }
    }

之后,我创建了存储过程 Login

CREATE PROCEDURE [dbo].[Login] (
   @UserNameLogin NCHAR (20), 
   @UserPasswordLogin NCHAR (30)
   )
AS
   SELECT * FROM [Us] WHERE UserName=@UserNameLogin AND UserPassword=@UserPasswordLogin
RETURN 0

最后,我用后面的代码连接了

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;
               }

问题在哪里?System.Data.SqlClient.SqlException(0x80131904)。Procedure or function 'Login' expects parameter '@UserNameLogin', which was not supplied.

我需要configurationManager吗? 如果是的话,如何写正确的代码?

c# sql-server web-services
1个回答
1
投票

我认为你必须指定 com.CommandType = CommandType.StoredProcedure;

© www.soinside.com 2019 - 2024. All rights reserved.