Answered by:
Update command not working!

Question
-
User2127600007 posted
what is the problem
public string crypt(string origPass) { Byte[] truePass; Byte[] encodePass; MD5 convert = new MD5CryptoServiceProvider(); truePass = ASCIIEncoding.Default.GetBytes(TextBox1.Text); encodePass = convert.ComputeHash(truePass); return BitConverter.ToString(encodePass); } protected void Button2_Click(object sender, EventArgs e) { try { LogInDataContext db = new LogInDataContext(); var newUser = (from u in db.Accesses where u.AccessPassword == TextBox1.Text select u).Single(); newUser.AccessPassword = crypt(TextBox1.Text); db.SubmitChanges(); Response.Write("<script>alert('Password has been changed, try logging in!')</script>"); Server.Transfer("LogInPage.aspx"); } catch { Response.Write("<script>alert('Password change failed!')</script>"); } }
Tuesday, August 2, 2011 7:46 AM
Answers
-
User44080657 posted
Two things i would check first.
1. Ensure that the table you are trying to update has a primary key.
2. Ensure that your query is actually returning a record.
Are you recieving an error?
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, August 2, 2011 10:24 AM -
User3866881 posted
Hello scrollLock:)
Please debug your app and tell us whether you can debug and the debug trace can enter into your Button2_Click, what's the result, plz tell us.
Thx again
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, August 3, 2011 10:05 PM -
User3866881 posted
when i run the application, the catch statement takes effect, meaning the try statement is somewhat wrong.
Hello:)
Plz have a try like this——
var newUser = (from u in db.Accesses
where
u.AccessPassword == TextBox1.Text
select u).FirstOrDefault();if (newUser!=null)
{
newUser.AccessPassword = crypt(TextBox1.Text);
db.SubmitChanges();}
If still fails, plz remove try……catch and tell me what's err msg?
Thx again
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, August 4, 2011 9:06 PM -
User3866881 posted
Hello again:)
Sorry I didn't catch your meaning well……
Have you used my codes?
And would you mind showing me your screenshot of your error msg after removing try……catch……block?
Thx again
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, August 4, 2011 9:27 PM -
User3866881 posted
with try catch > ON!
Well……I feel very strange——Since the dialog pop ups to tell you that your password has been successfully changed. Why it still executes "catch" codes?
with try catch > OFF!Since your try catch>ON will pop up password change fails dialog, which means there's something wrong (or problem) of your codes an some exception happened. But if you remove try…… catch…… Everything goes well no thrown exceptions???
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Friday, August 5, 2011 9:03 PM -
User3866881 posted
Hello again:)
Plz check the value in the db, is it changed or not?
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Saturday, August 6, 2011 2:54 AM -
User1957418580 posted
Please go back to the begining and try Decker's code do make sure that "newUser" is not null. SubmitChanges doesn't always give an error when it doesn't work - it's possible you aren't even connected to the database as I've seen a simple connetionstring problem fail to perform an insert without error. Also, have you made sure that the table has a primary key?
At this point, if it still fails, you might need to make a small project and post it so that we have the whole thing to work with in order to help.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, August 8, 2011 6:56 AM -
User-662335483 posted
Plz check both value us enter and in database is same or not
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, August 8, 2011 9:44 AM -
User1957418580 posted
Is newUser null?
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, August 9, 2011 4:00 PM -
User1957418580 posted
As a test, does it update if you don't encrypt the TextBox value? Is it possible that it's updating but the textbox value is empty?
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, August 18, 2011 10:15 AM
All replies
-
User44080657 posted
Two things i would check first.
1. Ensure that the table you are trying to update has a primary key.
2. Ensure that your query is actually returning a record.
Are you recieving an error?
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, August 2, 2011 10:24 AM -
User2127600007 posted
it is already working,, prefer to this topic i made >> http://forums.asp.net/t/1705772.aspx/1?Things+not+appearing+in+Ajax+Toolkit+Tab+Why+
when i put my things in the first tab, its ok, but when i put things on other tabs, that's where it dont show up.
Wednesday, August 3, 2011 8:14 AM -
User3866881 posted
Hello scrollLock:)
Please debug your app and tell us whether you can debug and the debug trace can enter into your Button2_Click, what's the result, plz tell us.
Thx again
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, August 3, 2011 10:05 PM -
User2127600007 posted
when i run the application, the catch statement takes effect, meaning the try statement is somewhat wrong.
Thursday, August 4, 2011 8:52 PM -
User3866881 posted
when i run the application, the catch statement takes effect, meaning the try statement is somewhat wrong.
Hello:)
Plz have a try like this——
var newUser = (from u in db.Accesses
where
u.AccessPassword == TextBox1.Text
select u).FirstOrDefault();if (newUser!=null)
{
newUser.AccessPassword = crypt(TextBox1.Text);
db.SubmitChanges();}
If still fails, plz remove try……catch and tell me what's err msg?
Thx again
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, August 4, 2011 9:06 PM -
User2127600007 posted
1st
Password has been changed, try logging in!
thenpassword change failed
after removing try catch, same error
but the password doesnt change, i tried loggin in with new password
Thursday, August 4, 2011 9:18 PM -
User3866881 posted
Hello again:)
Sorry I didn't catch your meaning well……
Have you used my codes?
And would you mind showing me your screenshot of your error msg after removing try……catch……block?
Thx again
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, August 4, 2011 9:27 PM -
User2127600007 posted
with try catch > ON!
with try catch > OFF!
--PASSWORD DONT CHANGE EVEN THE ALERT BOX TELL IT ALREADY CHANGED--
Friday, August 5, 2011 9:17 AM -
User3866881 posted
with try catch > ON!
Well……I feel very strange——Since the dialog pop ups to tell you that your password has been successfully changed. Why it still executes "catch" codes?
with try catch > OFF!Since your try catch>ON will pop up password change fails dialog, which means there's something wrong (or problem) of your codes an some exception happened. But if you remove try…… catch…… Everything goes well no thrown exceptions???
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Friday, August 5, 2011 9:03 PM -
User2127600007 posted
^
when removing try catch, the alert box tells that "its a success" but when i tried logging in with the new password, it doesnt accept the new password.so, the alert box is a lie!
Friday, August 5, 2011 9:25 PM -
User3866881 posted
Hello again:)
Plz check the value in the db, is it changed or not?
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Saturday, August 6, 2011 2:54 AM -
User1957418580 posted
Please go back to the begining and try Decker's code do make sure that "newUser" is not null. SubmitChanges doesn't always give an error when it doesn't work - it's possible you aren't even connected to the database as I've seen a simple connetionstring problem fail to perform an insert without error. Also, have you made sure that the table has a primary key?
At this point, if it still fails, you might need to make a small project and post it so that we have the whole thing to work with in order to help.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, August 8, 2011 6:56 AM -
User-662335483 posted
Plz check both value us enter and in database is same or not
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, August 8, 2011 9:44 AM -
User2127600007 posted
Monday, August 8, 2011 10:04 AM -
User1957418580 posted
Is newUser null?
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, August 9, 2011 4:00 PM -
User2127600007 posted
newuser is not null.
Wednesday, August 10, 2011 9:47 AM -
User1957418580 posted
As a test, does it update if you don't encrypt the TextBox value? Is it possible that it's updating but the textbox value is empty?
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, August 18, 2011 10:15 AM