Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7944063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T00:27:04+00:00 2026-06-04T00:27:04+00:00

I have created the EF model and then in a Class I have written

  • 0

I have created the EF model and then in a Class I have written the following Code to retrieve the value form the DataBase. And store the value in another Table. But it gives me the Error “DATAREADER IS INCompatable” as explained Below..

      EmpRole empr = new EmpRole();
        empr.EmpId = strEmpId;
      string str="select RoleId from RoleName where roleName like '"+strDesignation+"'";
      var context= DbAccess.Data.ExecuteStoreQuery<RoleName>(str, null);  //Here Showing Error

        empr.RoleId = Convert.ToInt16(context);
        DbAccess.Data.EmpRoles.AddObject(empr);
        DbAccess.Commit();

It’s showing the error like:

DataTables were:

CREATE TABLE [dbo].[RoleName](
    [SNo] [int] IDENTITY(1,1) NOT NULL,
    [RoleId] [smallint] NOT NULL,
    [RoleName] [varchar](50) NULL,
 CONSTRAINT [PK_RoleName] PRIMARY KEY CLUSTERED 
(
    [RoleId] ASC
)

CREATE TABLE [dbo].[EmpRoles](
    [Sno] [int] IDENTITY(1,1) NOT NULL,
    [EmpId] [varchar](8) NOT NULL,
    [RoleId] [smallint] NOT NULL,
    [ReportingToId] [varchar](8) NULL,
 CONSTRAINT [PK_EmpRoles] PRIMARY KEY CLUSTERED 
(
    [Sno] ASC
)

The data reader is incompatible with the specified ‘MyOrgDBModel.RoleName’. A member of the type, ‘SNo’, does not have a corresponding column in the data reader with the same name.

Please tell me the reasons what to do to execute the sqlQuery.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T00:27:06+00:00Added an answer on June 4, 2026 at 12:27 am

    This is because you are not selecting the SNo column in your select query. As you are populating in RoleName and it has property SNo column should be present in data reader. If you just want the RoleId to be in query then create new type with one property RoleId and use this. Create new type like below

    public class CustomRoleName
    {
        int RoleId { get; set; }
    }
    

    Now change your code as follow

    EmpRole empr = new EmpRole();
    empr.EmpId = strEmpId;
    string str="select RoleId from RoleName where roleName like '"+strDesignation+"'";
    foreach(CustomRoleName rn in  DbAccess.Data.ExecuteStoreQuery<CustomRoleName>(str))
    {
         empr.RoleId = rn.RoleId ;
         DbAccess.Data.EmpRoles.AddObject(empr);
         DbAccess.Commit();
         break;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Model created with a table called Customers. It contains the following
if i have created a view model and have a partial form that is
I have created an entity data model and generated a database from it. One
i have created the folloiwng view model class public class viewmodelclass { public IEnumerable<Question>
I have created a model which attaches media to blog posts: class MediaAttachment(models.Model): media
Ok... So I have created my model using EF4. Great! I then turned off
I created the following class to model a person: namespace DataBindingTest { public enum
I have created my own class that derives from QTableView, the associated model is
I have created model, controller and view with rails scaffold generator: rails g scaffold
I have created a model test case in a plugin. Plugin name: Filters and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.