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
Guest User
Tech Writer
271
35.9k
save image to database in asp.net Using Entity framework
Aug 4 2020 5:52 AM
Hello...
I want to save image path in database... I am using fileupload and also give path but the problem is it is not saving in the database...
protected
void
Button1_Click(
object
sender, EventArgs e)
{
Model.User newusermodel =
new
Model.User();
newusermodel.Image = TxtImg.ToString();
newusermodel.Name = TxtName.Text;
newusermodel.UserName = TxtUserName.Text;
newusermodel.EmailID = TxtEmailID.Text;
newusermodel.Created_Date = DateTime.Now;
newusermodel.User_Type_Id = 3;
newusermodel.Password = TxtPassword.Text;
using
(WallpaperEntities4 context =
new
WallpaperEntities4())
{
User user =
new
User();
{
string
str = TxtImg.FileName;
TxtImg.PostedFile.SaveAs(Server.MapPath(
"~/Upload/"
+ str));
string
Image =
"~/Upload/"
+ str.ToString();
string
name = TxtImg.ToString();
user.Image = newusermodel.Image;
user.Name = newusermodel.Name;
user.UserName = newusermodel.UserName;
user.EmailID = newusermodel.EmailID;
user.Created_Date = newusermodel.Created_Date;
user.User_Type_Id = newusermodel.User_Type_Id;
user.Password = newusermodel.Password;
};
var usersadd = context.Set<User>();
var response = context.Users.Where(u => u.UserName == newusermodel.UserName).FirstOrDefault();
if
(response ==
null
)
{
usersadd.Add(user);
context.SaveChanges();
Response.Redirect(
"/Login.aspx"
);
}
else
{
LblMesge.Text =
"User exists"
;
}
Attachment:
fileup_(2).zip
Reply
Answers (
2
)
For a .NET developer interview, what are the main technical questions
Is it worth learning ADO.NET?