Hi,
How to update one text box value into 2 columns in database in MVC 5.
Thanks,
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Jignesh TrivediRank #16 · 50.3K reputationPosted Mar 18, 2015, 7:58 PM EDT
It depends on which technologies you are using as DAL.
If you are using ADO.net than agree with Afzaal.
if you are using EF than assign same value to two properties of entity model
Entitycontext context = new Entitycontext();
Table1 t = new Table1();
t.Col1 = value;
t.Col2 = value
context.Table1.Add(t);
context.SaveChanges();
hope this will help you.
Afzaal Ahmad ZeeshanRank #60 · 27.6K reputationPosted Mar 18, 2015, 1:21 PM EDT
SqlCommand command = new SqlCommand("UPDATE table_name SET column1 = @value, column2 = @value", conn);
command.Parameters.Add("@value", textBox1.Text);
Now when this would execute, both the columns would have similar value.
neel k143 reputationPosted Mar 19, 2015, 5:51 AM EDT
if (list.Count > 0)
{
if (ModelState.IsValid)
{
external_applications ea = new external_applications();
ea.loginURL_development = dbAppEdit_old.loginURL_development;
ea.loginURL_production = dbAppEdit_old.loginURL_development; ea.registrationURL_development = dbAppEdit_old.registrationURL_development; ea.registrationURL_production = dbAppEdit_old.registrationURL_development; db.external_applications.Add(ea); //db.external_applications.Attach(application_new); db.Entry(ea).State = System.Data.Entity.EntityState.Modified; //db.external_applications.Find(application_new.description); db.SaveChanges();
}
}
Jignesh TrivediRank #16 · 50.3K reputationPosted Mar 19, 2015, 6:10 AM EDT
Hi,
you entity contain validation error. please refer below link it help you how to see the error.
first resolve it and perform save change()
http://mattrandle.me/viewing-entityvalidationerrors-in-visual-studio/
http://www.c-sharpcorner.com/UploadFile/97fc7a/validation-failed-for-one-or-more-entities-mvcentity-frame/
hope this will help you.