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
sangeetha k
NA
207
51.6k
An exception of type 'System.NotSupportedException' occurred
Mar 23 2018 6:06 AM
#controller
public
ActionResult Employee(
int
txtEmployeeId,
string
txtEmployeeName,
string
txtEmployeeDesignation, HttpPostedFileBase Empimage,
double
txtSalary,
string
txtEmployeeDpt,
byte
[] bytes)
{
EmployeeBusiness EmpBusiness =
new
EmployeeBusiness();
EmployeeEntity emp =
new
EmployeeEntity();
emp.Empid = Convert.ToInt32(txtEmployeeId);
emp.Empname = txtEmployeeName;
emp.Designation = txtEmployeeDesignation;
emp.Salary = Convert.ToDouble(txtSalary);
emp.Department = txtEmployeeDpt;
emp.Empimage = savetophysicallocation(Empimage);
EmpBusiness.saveEmployeeDetails(emp);
return
View();
}
private
string
savetophysicallocation(HttpPostedFileBase Empimage)
{
if
(Empimage.ContentLength>0){
var fileName=Path.GetFileName(Empimage.FileName);
var upload=
"~/C:/Users/sangeetha.k/Desktop/images"
;
var path = Path.Combine(Server.MapPath(upload), fileName);
Empimage.SaveAs(path);
return
path;
}
return
string
.Empty;
}
}
}
#Business Layer
namespace
EmployeeBusinessLayer
{
public
class
EmployeeBusiness
{
EmployeeDataAcess empdata =
new
EmployeeDataAcess();
public
void
saveEmployeeDetails(EmployeeEntity emp)
{
empdata.saveEmployeeDetails(emp);
}
}
}
#Data AccessLayer
public
class
EmployeeDataAcess
{
string
ConnectionString = ConfigurationManager.ConnectionStrings[
"Employee"
].ConnectionString;
AdventureWorksEntities EmpDbEntity =
new
AdventureWorksEntities();
tblEmployee EmployeeDbContext =
new
tblEmployee();
public
void
saveEmployeeDetails(EmployeeEntity emp)
{
using
(AdventureWorksEntities EmpDbEntity =
new
AdventureWorksEntities())
{
tblEmployee EmployeeDbContext =
null
;
if
(EmpDbEntity.tblEmployees==
null
)
{
EmployeeDbContext.Empid = emp.Empid;
EmployeeDbContext.Empname = emp.Empname;
EmployeeDbContext.Designation = emp.Designation;
EmployeeDbContext.Empimage = emp.Empimage;
EmployeeDbContext.Empimage = emp.Empimage;
EmployeeDbContext.Salary = emp.Salary;
EmployeeDbContext.Email = emp.Email;
EmployeeDbContext.Department = emp.Department;
}
if
(EmpDbEntity.tblEmployees!=
null
)
{
EmployeeDbContext = EmpDbEntity.tblEmployees.Where(x => x.Empid == emp.Empid).FirstOrDefault();
}
}
}
}
}
and #entity Layer
public
class
EmployeeEntity
{
public
int
Empid {
get
;
set
; }
public
string
Empname {
get
;
set
; }
public
string
Designation {
get
;
set
; }
public
string
Empimage {
get
;
set
; }
public
byte
[] ImageData {
get
;
set
; }
public
Nullable<
double
> Salary {
get
;
set
; }
public
string
Email {
get
;
set
; }
public
string
Department {
get
;
set
; }
//public EmployeeEntity()
//{
//}
//public EmployeeEntity(int Empid, string Empname, string Designation, string Empimage, byte[] ImageData, double Salary, string Email, string Department)
//{
// this.Empid = Empid;
// this.Empname = Empname;
// this.Designation = Designation;
// this.Empimage = Empimage;
// this.ImageData = ImageData;
// this.Salary = Salary;
// this.Email = Email;
// this.Department = Department;
}
}
#sql Table structure
Empid int
Empname nvarchar
Designation nvarchar
Empimage nvarchar
ImageData varbinary
Salary float
Email nvarchar
Department nvarchar
Reply
Answers (
6
)
confused about learning
Loop Didn't Work Properly, 1 Row Only Update From Grid