BusinessBase Update Fails without ErrorBusinessBase Update Fails without Error
Old forum URL: forums.lhotka.net/forums/t/6563.aspx
davidc posted on Thursday, March 05, 2009
My insert works but my update does not. When I call the save it comes back saying that it is dirty and valid never gets to the DataPortal_Update().
public
override Customer Save()
{
_lastname = _lastname + "1";
if (IsDeleted && !CanDeleteObject())
throw new System.Security.SecurityException("User not authorized to remove a project");
else if (IsNew && !CanAddObject())
throw new System.Security.SecurityException("User not authorized to add a project");
else if (!CanEditObject())
throw new System.Security.SecurityException("User not authorized to update a project");
_lastname = _lastname +
"2";
if (base.IsDirty == true)
{
_lastname = _lastname + "3";
}
if (base.IsSavable == true)
{
_lastname = _lastname + "4";
}
if (base.IsValid == true)
{
_lastname = _lastname + "5";
}
return base.Save();
}
protected
override void DataPortal_Update()
{
_lastname = _lastname + "6";
if (base.IsDirty)
{
using (SqlConnection cn = new SqlConnection(Database.cmsConnection))
{
cn.Open();
using (SqlCommand cm = cn.CreateCommand())
{
_lastname = _lastname + "7";
cm.CommandText = "updateUser";
DoInsertUpdate(cm);
_lastname = _lastname + "9";
}
}
}
}
private void DoInsertUpdate(SqlCommand cm)
{
_lastname = _lastname + "8";
cm.CommandType = CommandType.StoredProcedure;
cm.Parameters.AddWithValue("@UserId", _userid);
cm.Parameters.AddWithValue("@Pwd", _pwd);
cm.Parameters.AddWithValue("@FirstName", _firstname);
cm.Parameters.AddWithValue("@Middle", _middle);
cm.Parameters.AddWithValue("@LastName", _lastname);
cm.Parameters.AddWithValue("@Phone", _phone);
cm.Parameters.AddWithValue("@Email", _email);
cm.Parameters.AddWithValue("@Street", _street);
cm.Parameters.AddWithValue("@City", _city);
cm.Parameters.AddWithValue("@State", _state);
cm.Parameters.AddWithValue("@Zip", _zip);
cm.Parameters.AddWithValue("@CompanyName", _companyname);
cm.Parameters.AddWithValue("@TemplateId", _templateId);
cm.Parameters.AddWithValue("@LogoType", _logotype);
cm.ExecuteNonQuery();
}
I output the last name and it makes it all the way to the number 5.
Marjon1 replied on Thursday, March 05, 2009
Have you tried putting a break on your DataPortal_Insert() method?
The only reason I can think of is if you object thinks that it is still new.
Is this an object that you are retrieving via a dataportal_fetch() and then making changes and then attempting to save; or is a new object, you save changes and then make more changes to fire the update?
davidc replied on Friday, March 06, 2009
Yes I use the same object to fetch and populate a FormView. Then I edit the last name and click update and it comes back saying updated successfull and "LastName12345".
Also I don't have any maxlength set on the last name and even when I put test in for the last name it comes back "test12345". It is a string in the BO and a varchar(50) in the database
IanK replied on Friday, March 06, 2009
It may not be a great idea to change property in object after you call the save as 1 appending to field may in fact be breaking a rule such as a MaxLength you may have set and you also may be affecting the editlevel the object is at which in turn will cause your save to fail.
Copyright (c) Marimer LLC