用户代码未处理无效的强制转换异常

时间:2015-01-05 10:08:41

标签: asp.net exception

public ClientApp_Detail GetHomeDetbyClientID_AppID(string clientid, long appId)
    {
        ClientApp_Detail sp = null;
        using (HelpDeskDataContext HDDC = Conn.GetContext())
        {
           sp = (from st in HDDC.ClientApp_Details where  st.ClientID == clientid && st.AppID == Convert.ToInt64(appId) && st.IsDeleted != 1 select st).FirstOrDefault();
        }
        return sp;
    }

对于上面的.net代码我得到了例外,即用户代码未处理无效的强制转换异常。 但是所有的值都是精确的数据类型,即st.ClientID和clientid分别是varchar(50)和字符串,AppId,appid是longint IsDeleted是位,那么错误的原因是什么,如果有任何疑问,请推荐任何有关此问题发送详细信息。 谢谢。

[全球:: System.Data.Linq.Mapping.TableAttribute(名称= “dbo.ClientApp_Details”)]     public partial class ClientApp_Detail:INotifyPropertyChanging,INotifyPropertyChanged     {

    private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty);

    private string _ClientID;

    private long _AppID;

    private string _ProjectScope;

    private string _ProjectStatus;

    private System.DateTime _StrDt;

    private System.DateTime _EndDt;

    private double _NoofHours;

    private long _ID;

    private System.Data.Linq.Binary _TimeStamp;

    //sumanth edit
    private bool _IsDeleted;


    private System.Nullable<System.DateTime> _CreationDt;

#region Extensibility Method Definitions
partial void OnLoaded();
partial void OnValidate(System.Data.Linq.ChangeAction action);
partial void OnCreated();
partial void OnClientIDChanging(string value);
partial void OnClientIDChanged();
partial void OnAppIDChanging(long value);
partial void OnAppIDChanged();
partial void OnProjectScopeChanging(string value);
partial void OnProjectScopeChanged();
partial void OnProjectStatusChanging(string value);
partial void OnProjectStatusChanged();
partial void OnStrDtChanging(System.DateTime value);
partial void OnStrDtChanged();
partial void OnEndDtChanging(System.DateTime value);
partial void OnEndDtChanged();
partial void OnNoofHoursChanging(double value);
partial void OnNoofHoursChanged();
partial void OnIDChanging(long value);
partial void OnIDChanged();
partial void OnTimeStampChanging(System.Data.Linq.Binary value);
partial void OnTimeStampChanged();
partial void OnIsDeletedChanging(bool value);
partial void OnIsDeletedChanged();
partial void OnCreationDtChanging(System.Nullable<System.DateTime> value);
partial void OnCreationDtChanged();
#endregion

    public ClientApp_Detail()
    {
        OnCreated();
    }

    [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_ClientID", DbType="VarChar(50) NOT NULL", CanBeNull=false, UpdateCheck=UpdateCheck.Never)]
    public string ClientID
    {
        get
        {
            return this._ClientID;
        }
        set
        {
            if ((this._ClientID != value))
            {
                this.OnClientIDChanging(value);
                this.SendPropertyChanging();
                this._ClientID = value;
                this.SendPropertyChanged("ClientID");
                this.OnClientIDChanged();
            }
        }
    }

    [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_AppID", DbType="BigInt NOT NULL", UpdateCheck=UpdateCheck.Never)]
    public long AppID
    {
        get
        {
            return this._AppID;
        }
        set
        {
            if ((this._AppID != value))
            {
                this.OnAppIDChanging(value);
                this.SendPropertyChanging();
                this._AppID = value;
                this.SendPropertyChanged("AppID");
                this.OnAppIDChanged();
            }
        }
    }

    [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_ProjectScope", DbType="Text", UpdateCheck=UpdateCheck.Never)]
    public string ProjectScope
    {
        get
        {
            return this._ProjectScope;
        }
        set
        {
            if ((this._ProjectScope != value))
            {
                this.OnProjectScopeChanging(value);
                this.SendPropertyChanging();
                this._ProjectScope = value;
                this.SendPropertyChanged("ProjectScope");
                this.OnProjectScopeChanged();
            }
        }
    }

    [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_ProjectStatus", DbType="Text", UpdateCheck=UpdateCheck.Never)]
    public string ProjectStatus
    {
        get
        {
            return this._ProjectStatus;
        }
        set
        {
            if ((this._ProjectStatus != value))
            {
                this.OnProjectStatusChanging(value);
                this.SendPropertyChanging();
                this._ProjectStatus = value;
                this.SendPropertyChanged("ProjectStatus");
                this.OnProjectStatusChanged();
            }
        }
    }

    [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_StrDt", DbType="DateTime NOT NULL", UpdateCheck=UpdateCheck.Never)]
    public System.DateTime StrDt
    {
        get
        {
            return this._StrDt;
        }
        set
        {
            if ((this._StrDt != value))
            {
                this.OnStrDtChanging(value);
                this.SendPropertyChanging();
                this._StrDt = value;
                this.SendPropertyChanged("StrDt");
                this.OnStrDtChanged();
            }
        }
    }

    [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_EndDt", DbType="DateTime NOT NULL", UpdateCheck=UpdateCheck.Never)]
    public System.DateTime EndDt
    {
        get
        {
            return this._EndDt;
        }
        set
        {
            if ((this._EndDt != value))
            {
                this.OnEndDtChanging(value);
                this.SendPropertyChanging();
                this._EndDt = value;
                this.SendPropertyChanged("EndDt");
                this.OnEndDtChanged();
            }
        }
    }

    [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_NoofHours", DbType="Float NOT NULL", UpdateCheck=UpdateCheck.Never)]
    public double NoofHours
    {
        get
        {
            return this._NoofHours;
        }
        set
        {
            if ((this._NoofHours != value))
            {
                this.OnNoofHoursChanging(value);
                this.SendPropertyChanging();
                this._NoofHours = value;
                this.SendPropertyChanged("NoofHours");
                this.OnNoofHoursChanged();
            }
        }
    }

    [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_ID", AutoSync=AutoSync.OnInsert, DbType="BigInt NOT NULL IDENTITY", IsPrimaryKey=true, IsDbGenerated=true, UpdateCheck=UpdateCheck.Never)]
    public long ID
    {
        get
        {
            return this._ID;
        }
        set
        {
            if ((this._ID != value))
            {
                this.OnIDChanging(value);
                this.SendPropertyChanging();
                this._ID = value;
                this.SendPropertyChanged("ID");
                this.OnIDChanged();
            }
        }
    }

    [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_TimeStamp", AutoSync=AutoSync.Always, DbType="rowversion NOT NULL", CanBeNull=false, IsDbGenerated=true, IsVersion=true, UpdateCheck=UpdateCheck.Never)]
    public System.Data.Linq.Binary TimeStamp
    {
        get
        {
            return this._TimeStamp;
        }
        set
        {
            if ((this._TimeStamp != value))
            {
                this.OnTimeStampChanging(value);
                this.SendPropertyChanging();
                this._TimeStamp = value;
                this.SendPropertyChanged("TimeStamp");
                this.OnTimeStampChanged();
            }
        }
    }

    [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_IsDeleted", DbType="Bit NOT NULL", UpdateCheck=UpdateCheck.Never)]
    public bool IsDeleted
    {
        get
        {
            return this._IsDeleted;
        }
        set
        {
            if ((this._IsDeleted != value))
            {
                this.OnIsDeletedChanging(value);
                this.SendPropertyChanging();
                this._IsDeleted = value;
                this.SendPropertyChanged("IsDeleted");
                this.OnIsDeletedChanged();
            }
        }
    }

0 个答案:

没有答案