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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Jignesh TrivediPosted Mar 18, 2015, 11:58 PM
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.
Jignesh TrivediPosted Mar 19, 2015, 10:10 AM
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.
neel kPosted Mar 19, 2015, 9:51 AM
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();
}
}
Afzaal Ahmad ZeeshanPosted Mar 18, 2015, 5:21 PM
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.