Click here to Skip to main content
15,880,543 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a MVC project in which i generate drop-down dynamically from SQL. Now when the SQL returns the variables, it matches it with mvc model to map with variables. but in need only three model variable. bu t it shows that all the model variables must match the SQL variable. it seems like it is strongly typed model. it asks for all model variables where as i only need few variables from model to match with SQL query. Kindly Help as soon as possible

What I have tried:

i tried to modify the models as well as SQL query but all in vain
Posted
Updated 10-Feb-19 22:25pm
v3
Comments
Wastedtalent 11-Feb-19 2:59am    
Without the code it's hard to totally understand your issue, but I would imagine you may need a model for your SQL and the model for your view, and a service that maps between the two.
Sam_k_khan 11-Feb-19 3:03am    
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Login.Models
{
public class Datesheet
{
public string ExamName { get; internal set; }
public long Id { get; set; }
public string Name { get; set; }
public string Dated { get; set; }
public string MaxMarks { get; set; }
public string MinMarks { get; set; }
public string From { get; set; }
public string To { get; set; }
public string Type { get; set; }


}
}
Sam_k_khan 11-Feb-19 3:06am    
this is my model. from sql query i need only Name and Id of this project. But on load it asks that all model varaibles should be returned from sql
Sam_k_khan 11-Feb-19 3:07am    
sql query is as folllows:
select Id , Name from tbl_abcd

Now when this Id And Name is mapped with the model above it asks for all other variables of this model. something like strongly typed
Sam_k_khan 11-Feb-19 3:14am    
the error on my screen is

the data reader is incompatible with the specified 'Login.Models.Datesheet'. A member of the type, 'MaxMarks' does not have a corresponding column in the data reader with the same name

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900