TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Cassie Mod
NA
488
70k
Invalid Column (CollectorName) when try to create for info
Feb 2 2016 11:35 AM
hi,
I've got the following question, maybe somebody knows how to fix it. I use a gridview to display data. one of the data items is the CollectorID. However i want to change the collectorID to Collector name.
But when i do that, it says it isn't a valid column ( wich is because the column doesn't exist in the database). So for now i commenced everything out.
However how do i get it fixed and is it possible to fix ? please let me know.
Controller:
using
Kendo.Mvc.Extensions;
using
Kendo.Mvc.UI;
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Web.Mvc;
using
System.Web.Util;
using
TelerikMvcApp1.Models;
namespace
TelerikMvcApp1.Controllers
{
public
class
HomeController : Controller
{
public
ActionResult Index()
{
var programCollectorDataFilesStatus =
new
ProgramCollectorDataFilesStatus();
//var collectorsContext = new CollectorsContext();
// used to show collectorName but not working
//var collectorsList = collectorsContext.Col.ToList();
// used to show collectorName but nog working
using
(CollectorStatusContext collectorStatusContext =
new
CollectorStatusContext())
{
IEnumerable<CollectorStatus> collectorstatuslist = collectorStatusContext.Collectors.ToList();
List<CollectorStatus> dataObjects =
new
List<CollectorStatus>();
foreach (var workItem in collectorstatuslist)
{
dataObjects.Add(
new
CollectorStatus
{
ServiceRunning = workItem.ServiceRunning,
BatchCompleted = workItem.BatchCompleted,
BatchErrorID = workItem.BatchErrorID,
CollectorID = workItem.CollectorID,
LastBatchID = workItem.LastBatchID,
LastChecked = workItem.LastChecked,
LastStart = workItem.LastStart
});
}
foreach (var item in collectorstatuslist)
{
CollectorStatus col =
new
CollectorStatus();
col.CollectorID = item.CollectorID;
ViewBag.CollectorID = col.CollectorID;
}
programCollectorDataFilesStatus.CollectorStatus = collectorstatuslist;
}
using
(DataFilesStatusContext dataFilesStatusContext =
new
DataFilesStatusContext())
{
IEnumerable<DataFilesStatus> datafilesstatuslist = dataFilesStatusContext.DataFiles.ToList(); // it gives an error that CollectorName isn't a valid column
List<DataFilesStatus> dataObjects =
new
List<DataFilesStatus>();
foreach (var workItem in datafilesstatuslist)
{
dataObjects.Add(
new
DataFilesStatus
{
LastDataFileID = workItem.LastDataFileID,
DatFileName = workItem.DatFileName,
DataFileCompleted = workItem.DataFileCompleted,
DataFileErrorID = workItem.DataFileErrorID,
CollectorID = workItem.CollectorID,
//CollectorName = collectorsList.FirstOrDefault(co => co.CollectorID == workItem.CollectorID).CollectorName
});
}
programCollectorDataFilesStatus.DataFilesStatus = datafilesstatuslist;
}
using
(ProgramStatusContext programStatusContext =
new
ProgramStatusContext())
{
IEnumerable<ProgramStatus> programstatuslist = programStatusContext.Stats.ToList();
List<ProgramStatus> dataObjects =
new
List<ProgramStatus>();
foreach (var workItem in programstatuslist)
{
dataObjects.Add(
new
ProgramStatus
{
ProgramName = workItem.ProgramName,
ProgramLastRun = workItem.ProgramLastRun,
});
}
programCollectorDataFilesStatus.ProgramStatus = programstatuslist;
}
return
View(programCollectorDataFilesStatus);
}
public
ActionResult About()
{
ViewBag.Message =
"Your app description page."
;
return
View();
}
public
ActionResult Contact()
{
ViewBag.Message =
"Your contact page."
;
return
View();
}
public
ActionResult ResultCollectors_Read([DataSourceRequest]DataSourceRequest request)
{
return
Json(GetCollectors().ToDataSourceResult(request));
}
public
ActionResult ResultDatafiles_Read([DataSourceRequest]DataSourceRequest request)
{
return
Json(GetDataFiles().ToDataSourceResult(request));
}
private
static
IEnumerable<CollectorStatus> GetCollectors()
{
var programCollectorDataFilesStatus =
new
ProgramCollectorDataFilesStatus();
using
(CollectorStatusContext collectorStatusContext =
new
CollectorStatusContext())
{
IEnumerable<CollectorStatus> collectorstatuslist = collectorStatusContext.Collectors.ToList();
List<CollectorStatus> dataObjects =
new
List<CollectorStatus>();
foreach (var workItem in collectorstatuslist)
{
dataObjects.Add(
new
CollectorStatus
{
ServiceRunning = workItem.ServiceRunning,
BatchCompleted = workItem.BatchCompleted,
BatchErrorID = workItem.BatchErrorID,
CollectorID = workItem.CollectorID,
LastBatchID = workItem.LastBatchID,
LastChecked = workItem.LastChecked,
LastStart = workItem.LastStart
});
}
programCollectorDataFilesStatus.CollectorStatus = collectorstatuslist;
return
dataObjects;
}
}
private
static
IEnumerable<DataFilesStatus> GetDataFiles()
{
var programCollectorDataFilesStatus =
new
ProgramCollectorDataFilesStatus();
using
(DataFilesStatusContext dataFilesStatusContext =
new
DataFilesStatusContext())
{
IEnumerable<DataFilesStatus> datafilesstatuslist = dataFilesStatusContext.DataFiles.ToList();
List<DataFilesStatus> dataObjects =
new
List<DataFilesStatus>();
foreach (var workItem in datafilesstatuslist)
{
dataObjects.Add(
new
DataFilesStatus
{
LastDataFileID = workItem.LastDataFileID,
DatFileName = workItem.DatFileName,
DataFileCompleted = workItem.DataFileCompleted,
DataFileErrorID = workItem.DataFileErrorID,
CollectorID = workItem.CollectorID
});
}
programCollectorDataFilesStatus.DataFilesStatus = datafilesstatuslist;
return
dataObjects;
}
}
}
}
gridview:
@
using
TelerikMvcApp1.Models
@model ProgramCollectorDataFilesStatus
@(Html.Kendo().Grid<DataFilesStatus>()
.Name(
"DataFilesGrid"
)
.Columns(columns =>
{
columns.Bound(d => d.LastDataFileID);
columns.Bound(d => d.DatFileName);
columns.Bound(d => d.DataFileCompleted);
columns.Bound(d => d.DataFileErrorID);
//columns.Bound(d => d.CollectorName); // this doesn't work , invalid column
columns.Bound(d => d.CollectorID);
})
.Filterable()
.Sortable()
.Groupable()
.Pageable(pageable => pageable
.Refresh(
true
)
.PageSizes(
true
)
)
.DataSource(dataSource => dataSource
.Ajax()
.Read(read => read.Action(
"ResultDatafiles_Read"
,
"Home"
))
.PageSize(10)
)
)
Model:
using
System;
using
System.Collections.Generic;
using
System.ComponentModel.DataAnnotations;
using
System.ComponentModel.DataAnnotations.Schema;
using
System.Data.Entity;
using
System.Linq;
using
System.Web;
namespace
TelerikMvcApp1.Models
{
public
class
DataFilesStatus
{
[Key]
[Column(
"LastDataFileID"
)]
[Display(Name =
"Last DataFile ID"
)]
public
int
LastDataFileID { get; set; }
[Column(
"DatFileName"
)]
[Display(Name =
"Filename"
)]
public
string DatFileName { get; set; }
[Column(
"DataFileCompleted"
)]
[Display(Name =
"Completed"
)]
public
bool
? DataFileCompleted { get; set; }
[Column(
"DataFileErrorID"
)]
[Display(Name =
"Error ID"
)]
public
int
? DataFileErrorID { get; set; }
[Column(
"CollectorID"
)]
[Display(Name =
"Collector ID"
)]
public
int
? CollectorID { get; set; }
//public string CollectorName { get; set; } // this is not working !! ( not really exits but only used to get CollectorName instead of CollectorID
//public IEnumerable<BatchErrors> BatchErrors { get; set; }
//public IEnumerable<FileErrors> Fileerrors { get; set; }
}
}
Reply
Answers (
1
)
how to create a HR group website
Web.Config file - Pooling=off