Hi, I created my web form and use the fields on it to save data to SQL table on the first saving, however, when I use the same form to open the same data, and did some changes on the form, then resave it, from the debug, my updated fields of data do not
be recognized in the codes, so the result is the updated date are not resaved to SQL table.
key1 = Convert.ToInt32(Key.Text);
var query = (from c in db.Table1 where c.Key == key1 select c).First();
query.Prod_No = ProdNo.Text; // all of data in these fields are not the new updated data, it is still the old data I changed,
query.Desc1 = Desc1.Text; // all of data in these fields are not the new updated data, it is still the old data I changed,
query.Remark = Remark.Text; // all of data in these fields are not the new updated data, it is still the old data I changed,
lblresult.Text = "record was updated successfully";
lblresult.ForeColor = Color.Red;
}
I used the similar codes on other area, it works well, but not in here, do not know what is wrong. the db.SaveChanges() returns 1, it means the save is successfully. and the red message is displayed on the form.
as i mentioned, I have changed the data on these fields, but in debug mode, I can not see the updated data, it still shows the data before I updated. Since the updated data are not in these data fields, so the save is still saved the old data.
Are you loading ProdNo.Text; and Desc1.Text on Page_Load event? Maybe, when you loading these data initially, you are not doing it in
if (!IsPostBack) block. As a result, when you do the postback for saving data, your textboxes are overridden first by loading data from database and then same data is resaved. To test the scenario - add a DateTime field in the database and
update using DateTime.Now for each update. At least, you will know if issue is with postback or saving data.
Peter Cong
Member
527 Points
681 Posts
It is very strange, my current fields can not be recognized, anybody knows why?
Jan 24, 2013 08:28 PM|LINK
Hi, I created my web form and use the fields on it to save data to SQL table on the first saving, however, when I use the same form to open the same data, and did some changes on the form, then resave it, from the debug, my updated fields of data do not be recognized in the codes, so the result is the updated date are not resaved to SQL table.
key1 = Convert.ToInt32(Key.Text);
var query = (from c in db.Table1 where c.Key == key1 select c).First();
query.Prod_No = ProdNo.Text; // all of data in these fields are not the new updated data, it is still the old data I changed,
query.Desc1 = Desc1.Text; // all of data in these fields are not the new updated data, it is still the old data I changed,
query.Remark = Remark.Text; // all of data in these fields are not the new updated data, it is still the old data I changed,
.......
Does anybody knows why this happened? thanks
Rion William...
All-Star
26764 Points
4419 Posts
Re: It is very strange, my current fields can not be recognized, anybody knows why?
Jan 24, 2013 08:32 PM|LINK
What does your save code look like? It sounds like the code relating to your update or save isn't working properly.
Peter Cong
Member
527 Points
681 Posts
Re: It is very strange, my current fields can not be recognized, anybody knows why?
Jan 24, 2013 09:30 PM|LINK
these are the codes after the prvious code,
int rowAffected = db.SaveChanges();
if (rowAffected > 0)
{
lblresult.Text = "record was updated successfully";
lblresult.ForeColor = Color.Red;
}
I used the similar codes on other area, it works well, but not in here, do not know what is wrong. the db.SaveChanges() returns 1, it means the save is successfully. and the red message is displayed on the form.
as i mentioned, I have changed the data on these fields, but in debug mode, I can not see the updated data, it still shows the data before I updated. Since the updated data are not in these data fields, so the save is still saved the old data.
any idea?
shahed.kazi
All-Star
17953 Points
3635 Posts
Re: It is very strange, my current fields can not be recognized, anybody knows why?
Jan 25, 2013 03:09 AM|LINK
Are you loading ProdNo.Text; and Desc1.Text on Page_Load event? Maybe, when you loading these data initially, you are not doing it in if (!IsPostBack) block. As a result, when you do the postback for saving data, your textboxes are overridden first by loading data from database and then same data is resaved. To test the scenario - add a DateTime field in the database and update using DateTime.Now for each update. At least, you will know if issue is with postback or saving data.
.NET World |Captcha Control