ASP.NET MVC C# - 从对象类型System.String []到已知的托管提供程序本机类型

时间:2018-03-15 03:37:51

标签: c# ado.net

我的代码出了问题。有人可以帮助我。

  1. 运行" comm.ExecuteScalar();"时,收到错误消息。

  2. 错误消息说"从对象类型System.String []到已知的托管提供者本机类型不存在映射。"

  3. 附上我的存储过程。

  4. 代码:

    using (SqlConnection conn = new SqlConnection(System.Convert.ToString(database.DbConnect("database1"))))
    {
        var procedure = "sp_auth_sign_in";
        int result = 0;
        try
        {
            conn.Open();
            using (SqlCommand comm = new SqlCommand(procedure, conn))
            {
                comm.CommandType = CommandType.StoredProcedure;
                comm.Parameters.AddWithValue("@employeeid", model.EmployeeId);
                comm.Parameters.AddWithValue("@password", model.Password);
                comm.Parameters.Add("@emp_name", SqlDbType.VarChar, 50).Direction = ParameterDirection.Output;
                comm.Parameters.Add("@role_group", SqlDbType.VarChar, 2).Direction = ParameterDirection.Output;
                comm.Parameters.Add("@chg_pass", SqlDbType.Bit).Direction = ParameterDirection.Output;
                comm.Parameters.Add("@img_path", SqlDbType.VarChar, 1000).Direction = ParameterDirection.Output;
                comm.Parameters.Add("@division_group", SqlDbType.VarChar, 3).Direction = ParameterDirection.Output;
                comm.Parameters.Add("@department_group", SqlDbType.VarChar, 3).Direction = ParameterDirection.Output;
                comm.Parameters.Add("@firstname", SqlDbType.VarChar, 25).Direction = ParameterDirection.Output;
                comm.Parameters.Add("@logintries", SqlDbType.Int).Direction = ParameterDirection.Output;
                comm.Parameters.Add("@uname_docutrack", SqlDbType.VarChar, 50).Direction = ParameterDirection.Output;
                comm.Parameters.Add("@ustatus_docutrack", SqlDbType.Bit).Direction = ParameterDirection.Output;
                comm.Parameters.Add("@SignatoryInitial", SqlDbType.VarChar, 3).Direction = ParameterDirection.Output;
                comm.Parameters.Add("@result", SqlDbType.Int).Direction = ParameterDirection.Output;
                comm.ExecuteScalar(); // got an error here.
    

    sp_auth_sign_in过程的代码:

    CREATE procedure [dbo].[sp_auth_sign_in]
    @employeeid       varchar(25)='', /* username for contractors; employee id for */
    @password         varchar(25)='',
    @emp_name         varchar(50)  output,
    @role_group       varchar(2)   output,
    @chg_pass         bit          output,
    @img_path         varchar(100) output,
    @division_group   varchar(3)   output,
    @department_group varchar(3)   output,
    @firstname        varchar(25)  output,
    @logintries       int          output,
    @uname_docutrack  varchar(50)  output,
    @ustatus_docutrack  bit  output,
    @SignatoryInitial   varchar(3) output,
    @result           int output
    as
    
    /*****************************
    
      Date  : June 17, 2015
     *****************************/
    
    /* variable(s) */
    declare 
    @statvar    bit=0,
    @stat_tries tinyint=0,
    @passcode   int=0
    
    set @logintries = 0
    
    /* trim white space(s) */
    set @employeeid=dbo.fn_lrtrim(@employeeid)
    set @password=dbo.fn_lrtrim(@password)
    
    /* raise error for null entries or any */
    if(@employeeid='')
    begin
        set @result=1
        return 1
    end
    
    if(@password='')
    begin
        set @result=2
        return 2
    end
    
    /* check if username/employee id is valid.  */
    if not exists
    (
        select
            aum.employeeid
        from dbo.app_users_megaworld aum with (nolock)
        where aum.employeeid=@employeeid
    )
    begin
        set @result=3
        return 3
    end
    
    /* check if account is active */
    select
        @statvar=aur.active
    from dbo.app_users_roles aur with (nolock)
    where aur.employeeid=@employeeid
    if(@statvar=0)
    begin
        set @result=4
        return 4
    end
    
    /* count login attempts */
    select
        @stat_tries=aur.tries
    from dbo.app_users_roles aur with (nolock)
    where aur.employeeid=@employeeid
    if(@stat_tries>=5)
    begin
        /* deactivate account if tries>=3 */
        exec dbo.sp_app_users_active @employeeid, 0
    
        /* reset login attempt in effect for the account deactivation */
        exec dbo.sp_app_users_tries @employeeid, 0
    
        set @result=5
        return 5
    end
    
    /* check username and password combination */
    exec dbo.sp_crt_user_passcode @employeeid, @password, @passcode output
    if not exists
    (
        select
            aur.passcode
        from dbo.app_users_roles aur with (nolock)
        where aur.employeeid=@employeeid and aur.passcode=@passcode
    )
    begin
        /* increase counter for login attempt(s) */
        exec dbo.sp_app_users_tries @employeeid, 1
    
        select @logintries = tries from app_users_roles where employeeid = @employeeid
    
        set @result=6
        return 6
    end
    
    
    
    /* account is valid */
    /* reset counter for login attempt(s) */
    exec dbo.sp_app_users_tries @employeeid, 0
    
    /* raise flag for signing-in */
    exec dbo.sp_app_users_logon @employeeid, 1 -- <-- change to 1 in production
    
    /* output user's information */
    select
        --@emp_name=rtrim(upper(aum.firstname) + ' ' + upper(aum.lastname) + ' ' + upper(iif(aum.suffix='', '', aum.suffix))) ,
        @emp_name=rtrim(aum.firstname + ' ' + aum.lastname + ' ' + iif(aum.suffix='', '', aum.suffix)) ,
        @role_group=aur.role_group,
        @chg_pass=aur.chg_pass,
        @img_path=iif(aum.img_path is null or aum.img_path='','/Images/Avatar/avatar.jpg', aum.img_path),
        @division_group=aum.division_group,
        @department_group=aum.department_group,
        @firstname=upper(aum.firstname),
        @uname_docutrack = isnull(aud.username,''),
        @ustatus_docutrack = isnull(aud.accountstatus,0),
        @SignatoryInitial = isnull(aum.SignatureInitial, '')
    from dbo.app_users_megaworld aum with (nolock)
    inner join dbo.app_users_roles aur with (nolock)
        on aum.employeeid=aur.employeeid
    full join dbo.app_user_roles_docutrack aud
        on aum.employeeid = aud.employeeid and aud.systemtype = 'MyTracking'
    where aum.employeeid=@employeeid
    
    
    
    set @result=0
    return 0
    GO
    

    更新

    问题在于:

    comm.Parameters.AddWithValue("@employeeid", model.EmployeeId);
    
    comm.Parameters.AddWithValue("@password", model.Password);
    

    - 在我的storedproc中,employeeId的数据类型是varchar,但在我的模型视图中,它被设置为&#34; dynamic&#34;。

    - 我真的不知道这里发生了什么,因为我只是一个新手,但当我把它改成&#34; string&#34;时,效果很好。

    - 剩下的问题是我设置会话的时间。

    错误:

    Session["EmployeeID"] = model.EmployeeId.Replace(",", "").ToUpper;
    
    Error   2   Cannot convert method group 'ToUpper' to non-delegate type 'object'. Did you intend to invoke the method?
    
    
    
    
    namespace WMSPortal.Models
    {
        public class LoginViewModel
        {
    
            public string EmployeeId { get; set; }
           //public dynamic EmployeeId { get; set; }
    

0 个答案:

没有答案