Specified cast is not valid là lỗi gì năm 2024

Bạn xem lại cái Session["UserName"] của bạn, khi đăng nhập bạn gán cái gì vào. Nếu bạn đúng là gán cái UserName thôi, thì bạn thử ép kiểu chỗ up=>up.TaiKhoan == [string]Session["UserName"]

  • > Oh. Vậy bạn xem lại cái định dạng dữ liệu của bạn nha. Giữa lớp định nghĩa và CSDL nha. Ví dụ trong lớp định nghỉa là int nhưng CSDL lại là bigint thì => 100% là fail !
  • Gửi bởi giangcoi48k

    Nửa việt nửa anh gì đó bạn? Canhans là do thằng linq nó tự sinh ra, chứ class của nó là Canhan, table cũng là Canhan, không biết thì đừng có nói. Bạn xem lại cái Session["UserName"] của bạn, khi đăng nhập bạn gán cái gì vào. Nếu bạn đúng là gán cái UserName thôi, thì bạn thử ép kiểu chỗ up=>up.TaiKhoan == [string]Session["UserName"] Để mình đính chính lại 1 tí xem thử giangcoi48k nói câu không biết thì đừng có nói có đúng không nha! - UserName và Matkhau Không biết kiến thức mình có hạn hẹp hay không mà theo mình thì Linq không có tự động đặt tên Canhans hay Canhan cho mình đâu . Hãy nâng cấp lên Microsoft Edge để tận dụng các tính năng mới nhất, bản cập nhật bảo mật và hỗ trợ kỹ thuật.

    SqlDataReader.GetInt32[Int32] Method

  • Reference

    Definition

    Gets the value of the specified column as a 32-bit signed integer.

    public: override int GetInt32[int i];

    public: virtual int GetInt32[int i];

    public override int GetInt32 [int i];

    public int GetInt32 [int i];

    override this.GetInt32 : int -> int

    abstract member GetInt32 : int -> int override this.GetInt32 : int -> int

    Public Overrides Function GetInt32 [i As Integer] As Integer

    Public Function GetInt32 [i As Integer] As Integer

    Parameters

    i Int32 The zero-based column ordinal.

    Returns

    The value of the specified column.

    Implements

    Exceptions

    The specified cast is not valid.

    Remarks

    No conversions are performed; therefore, the data retrieved must already be a 32-bit signed integer. Call IsDBNull to check for null values before calling this method.

    Applies to

    See also

  • DataAdapters and DataReaders [ADO.NET]
  • SQL Server and ADO.NET
  • ADO.NET Overview

    Phản hồi

    Sắp ra mắt: Trong năm 2024, chúng tôi sẽ dần gỡ bỏ Sự cố với GitHub dưới dạng cơ chế phản hồi cho nội dung và thay thế bằng hệ thống phản hồi mới. Để biết thêm thông tin, hãy xem: //aka.ms/ContentUserFeedback. Gửi và xem ý kiến phản hồi dành cho

    Tài nguyên bổ sung

    Trong bài viết này

    I can't figure out why I am get this error message System.InvalidCastException: Specified cast is not valid. I am doing a loop to make copies of detail records. I am creating a reference to add to a lookup field. Any ideal what is causing this error message?

    //Instead of iterating through all the child records and creating one by one we can also use ExecuteMultiple method foreach [Entity retrieve in service.RetrieveMultiple[query].Entities] { //Remove the primary key of the retrieved associated record retrieve.Attributes.Remove["new_selectortemplatequestionid"]; retrieve.Attributes.Remove["new_selectortemplateid"]; //Set the primary key value to Guid.NewGuid[] retrieve.Id = Guid.NewGuid[]; EntityReference newselectorTemplateLookup = new EntityReference["new_selectortemplate", selectortemplateId]; retrieve.Attributes.Add["new_selectortemplateid", newselectorTemplateLookup]; service.Create[retrieve]; }
  • RE: Plugin Error message - System.InvalidCastException: Specified cast is not valid. My problem had to do with another post operation trigger happening on another entity.
  • RE: Plugin Error message - System.InvalidCastException: Specified cast is not valid. Hi, Are you still getting the invalid case exception or something else? Can you try a small sample to create a copy of the record but with just one attribute to copy i.e. foreach record, create a new record and just add one field instead. Is working fine when you are running as async?
  • RE: Plugin Error message - System.InvalidCastException: Specified cast is not valid. Can I pay you for help. If so, how much an hour
  • RE: Plugin Error message - System.InvalidCastException: Specified cast is not valid.

    Hi, I am using a plugin post operation. The selectortemplateid is coming from the primary entity that is not committed. I am using "Aync". selectortemplateid = 12bf3c3b-5f2c-e811-80da-005056ba7ce0 I am creating a new entity and trying to copy detail entity from another entity. I am seeing the record in the table. The reference is not returning the name to the lookup. I believe this might be causing my error message. But not sure. If you notice from the image the lookup is not getting creating completely. The "ExtensionData" is null and the "Name" is null. Here is code that I am using. EntityReference newselectorTemplateLookup = SetReference["new_selectortemplate", selectortemplateId]; newselectorTemplateLookup.Name = selectortemplatename; questionTemplate.Attributes["new_selectortemplateid"] = newselectorTemplateLookup;

      
    
    Here the primary entity I tried to add the "Name" from the Primary but that still did not fix the error message.

    foreach [Entity _entity in result.Entities] { Entity questionTemplate = new Entity[_entity.LogicalName] { Id = Guid.NewGuid[] }; questionTemplate.Attributes.Add["new_name", _entity.GetAttributeValue["new_name"] ?? string.Empty]; questionTemplate.Attributes.Add["new_sectionid", _entity.GetAttributeValue["new_sectionid"]]; questionTemplate.Attributes.Add["new_questionid", _entity.GetAttributeValue["new_questionid"]]; EntityReference newselectorTemplateLookup = SetReference["new_selectortemplate", selectortemplateId];

    newselectorTemplateLookup.Name = selectortemplatename;

    questionTemplate.Attributes["new_selectortemplateid"] = newselectorTemplateLookup; service.Create[questionTemplate]; }
  • RE: Plugin Error message - System.InvalidCastException: Specified cast is not valid. I decided to change the code to assign each attribute. Still getting the same error message.
                    // Loop through each detail record to copy  
                    EntityCollection result = service.RetrieveMultiple[query];  
                    foreach [Entity _entity in result.Entities]  
                    {  
                        Entity questionTemplate = new Entity[];  
                        questionTemplate.LogicalName = _entity.LogicalName;  
                        questionTemplate.Id = Guid.NewGuid[];  
                        if [_entity.Attributes.Contains["new_name"]]  
                        {  
                            questionTemplate["new_name"] = _entity.Attributes["new_name"];  
                        }  
                        if [_entity.Attributes.Contains["new_sectionid"]]  
                        {  
                            EntityReference sectionLookup = [EntityReference]_entity.Attributes["new_sectionid"];  
                            questionTemplate["new_sectionid"] = sectionLookup;  
                        }  
                        if [_entity.Attributes.Contains["new_questionid"]]  
                        {  
                            EntityReference questionLookup = [EntityReference]_entity.Attributes["new_questionid"];  
                            questionTemplate["new_questionid"] = questionLookup;  
                        }  
                        if [_entity.Attributes.Contains["new_selectortemplateid"]]  
                        {  
                            EntityReference newselectorTemplateLookup = SetReference["new_selectortemplate", postImageSelectorTemplateId];  
                            questionTemplate["new_selectortemplateid"] = newselectorTemplateLookup;  
                        }  
                        service.Create[questionTemplate];  
                    }  
  • RE: Plugin Error message - System.InvalidCastException: Specified cast is not valid. I change the logic to add each attribute to make sure I was not missing anything. I am still getting the same error message. Here's my new code
                    // Loop through each detail record to copy  
                    EntityCollection result = service.RetrieveMultiple[query];  
                    foreach [Entity _entity in result.Entities]  
                    {  
                        Entity questionTemplate = new Entity[];  
                        questionTemplate.LogicalName = _entity.LogicalName;  
                        questionTemplate.Id = Guid.NewGuid[];  
                        if [_entity.Attributes.Contains["new_name"]]  
                        {  
                            questionTemplate["new_name"] = _entity.Attributes["new_name"];  
                        }  
                        if [_entity.Attributes.Contains["new_sectionid"]]  
                        {  
                            EntityReference sectionLookup = [EntityReference]_entity.Attributes["new_sectionid"];  
                            questionTemplate["new_sectionid"] = sectionLookup;  
                        }  
                        if [_entity.Attributes.Contains["new_questionid"]]  
                        {  
                            EntityReference questionLookup = [EntityReference]_entity.Attributes["new_questionid"];  
                            questionTemplate["new_questionid"] = questionLookup;  
                        }  
                        if [_entity.Attributes.Contains["new_selectortemplateid"]]  
                        {  
                            EntityReference newselectorTemplateLookup = SetReference["new_selectortemplate", postImageSelectorTemplateId];  
                            questionTemplate["new_selectortemplateid"] = newselectorTemplateLookup;  
                        }  
                        service.Create[questionTemplate];  
                    }  
  • RE: Plugin Error message - System.InvalidCastException: Specified cast is not valid. Did not work. Still getting same error message. RE: Plugin Error message - System.InvalidCastException: Specified cast is not valid. Hi, Can you check of you have any plugin registered on create of this entity? There doesn't seem anything wrond in this code.

Chủ Đề