//Check to make sure that no other user has the requested username DataTable dt = ds.Tables[0]; int iSelectedIndex = ListBoxUsers.SelectedIndex; if (iSelectedIndex == -1) { LabelFeedback.Text = "Click to select the user to update."; return; } DataRow dr = dt.Rows[iSelectedIndex]; int iUserID = (int) dr["UserID"]; string sUserName = Request.Form.Get("TextBoxUserName"); string sFilter = "UserName = \'" + sUserName + "\' and UserID <> " + iUserID; DataRow[] drOtherUsers = dt.Select(sFilter); if (drOtherUsers.Length > 0) { LabelFeedback.Text = "User " + drOtherUsers[0]["UserID"] + " has the UserName " + sUserName + ". " + "You cannot assign it to another user."; } else { //Update the fields dr["FirstName"] = Request.Form.Get("TextBoxFirstName"); dr["LastName"] = Request.Form.Get("TextBoxLastName"); dr["UserName"] = Request.Form.Get("TextBoxUserName"); dr["Pwd"] = Request.Form.Get("TextBoxPassword"); dr["Email"] = Request.Form.Get("TextBoxEmail"); //Update the database dataAdapter.Update(ds); //Write a success message LabelFeedback.Text = "This user's records were updated."; //Update the Listbox so the revised info appears there also PopulateListBox(); //Select the user who was just modified ListBoxUsers.SelectedIndex = iSelectedIndex; PopulateFieldsForSelectedUser(); }